NO Repeat of Background Image in CSS not working - html

I just tried out making a web page today and ran into a problem, looked everywhere to resolve the issue but didn't help please tell me what's I am doing wrong.
here is the HTML doc
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Astrology</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="mtl">
</div>
</body>
</html>
Here is the style.css
*
{
margin: 0;
padding: 0;
background-color: wheat;
background-size: cover;
}
*.mtl
{
height: 100vh;
background-image: url("./images/mars_p.jpg");
background-repeat: no-repeat;
background-position: -1844px 1160px;
}
Here is the picture when I put background-repeat: no-repeat;
And here is the picture after removing background-repeat: no-repeat;
Tell me why this no-repeat is not working

The background-repeat: no-repeat; is working just fine, the problem is with this line:
background-position: -1844px 1160px;
The picture moves to bottom-left of the screen too far and cannot be seen. You can only see it when you set the image to repeat or fix the background-position property smaller.

Related

how to cover/stretch an image across the entire page css/html?

body{
background-image: url("web.png");
background-repeat: no-repeat;
width: 100%;
}
This is the code i tried, but it is not working and i also tried to use screen width as default width for the entire image.
You can set the background size by using background-size property. In case of covering the whole page please use background-size: cover;.
body {
background-image: url("https://picsum.photos/1080/1920");
background-repeat: no-repeat;
background-size: cover;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- Your content here -->
</body>
</html>
To set the image as asked, you have to use background-size along with its attributes
(try these three and then select the one suitable for you)
body{
background-image: url("webp.png");
background-size: 100% 100%; /* used to set the image to fit 100% of the screen's width and height*/
}
body{
background-image: url("web.png");/* To cover the screen */
background-repeat: no-repeat;
background-size: cover;
}
body{
background-image: url("web.png");/*contains the image within the screen with with proper scale of the image*/
background-repeat: no-repeat;
background-size: contain;
}

Why doesnt the background cover the full html page?

So I tried everything that I know of and don't know why this isnt working please send help.
max-width/height didnt work there is always a small gap between html and border. And if I want to style the background with a linear gardient fo example there is always a small line wether it is right or at the bottom, I only can style it with th background-color. Here is the code:
html{
[![width: 100%;
height: 100%;
min-height: 100%;
min-width: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
overflow-x: hidden;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background: linear-gradient(to left, black, gray);][1]][1]
}
[1]: https://i.stack.imgur.com/N04VV.png
Try this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
body {
background: linear-gradient(to left,black, gray );
}
</style>
<body>
</body>
</html>

I'm having trouble with my websites background

The desktop version looks good, but the mobile version is clipping the background. What I mean by this is that when I scroll it has the effect of two backgrounds.
I don't know if the problem is in the css or the html file.
body, html{
height: 1080px;
margin: 0;
padding: 0;
background: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<!-- Required meta tags -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://use.fontawesome.com/releases/v5.0.6/js/all.js">
</script>
<link href="https://fonts.googleapis.com/css family=Montserrat:300,600,700i" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
Because you set background-image for two element (html and body). A simple webpage layout like this:
<html>
<head>
</head>
<body>
</body>
</html>
You can change the height value for the body, but not the html! The height value of HTML is always automatic. Therefore, after scrolling down 1080px, the body background ends and the html background is displayed. To solve the problem, just add the background to the body and remove height value.
body{
margin: 0;
padding: 0;
background-image: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
add this media code
#media screen and (max-width:500px){
body, html {
background-size:100% 100%;
}
}
You don't need to set bckgound for html and body. Only set the background for body.
body{ /* Remove html from this lie */
height: 1080px;
margin: 0;
padding: 0;
background: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}

Background image disappears after add some styles

pardon me if my question is stupid, I'm quick new to all these technologies. my objective is to add image-background in it default size while it doesn't zoom since it is a big size picture, the problem is when I add some styles, the image doesn't show up and background getting blank.
by the way, IM using particle.js on top of this background image.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Infinite Space !</title>
<link rel="stylesheet" href="style.css">
</head>
<body >
<div id="particles-js"></div>
//particle-js configues
<script src="https://cdn.jsdelivr.net/npm/particles.js#2.0.0/particles.min.js">
</script>
<script>
particlesJS.load('particles-js', 'particles.json', function() {
console.log('callback - particles.js config loaded');
});
</script>
</div>
</body>
</html>
#particles-js{
background: url("https://d14xs1qewsqjcd.cloudfront.net/assets/bg-header-star.jpg")
width: 100%;
min-height: 800px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed;
}
You didnt add a semicolon after the background property:
#particles-js{
background: url("https://d14xs1qewsqjcd.cloudfront.net/assets/bg-header-star.jpg") /* <---- Semicolon goes here*/
width: 100%;
min-height: 800px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed; /* Also you didnt close this comment */
}

CSS works in Internet Explorer but not Chrome or Firefox

Why does the code below work in IE, but not Firefox or Chrome? Is it the CSS or HTML?
CSS
body {
background-image:url("\images\body_bg.png");
background-repeat: repeat-x;
background-color:#e0dfe4;
background-attachment: scroll;
background-size: auto;
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="width=device-width, initial-scale=1.0"/>
<title>Program Letters</title>
<link rel="stylesheet" type="text/css" href="../general.css"/>
</head>
<body>...</body>
</html>
It was a location issue in the CSS. The modified code below fixed it.
body
{
background-position: inherit;
background-image: url("images/body_bg.jpg");
background-repeat: repeat-x;
background-color: #e0dfe4;
}