I am having an issue with my background image of a container being zoomed in on the browser. The picture is 1200px
wide and my container is also 1200px
wide. I have it set as the background-image for my .container selector. When I load it in the browser it is only showing a small portion of the image because it is zoomed in so far. Why is this happening?
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<main role="main">
<article role="article">
<section>
<header>
<div class="container">
</div>
</header>
</section>
</article>
</main>
</body>
</html>
CSS:
@font-face {
font-family: "Brandon Grotesque";
src: url("fonts/Brandon_Grotesque/Brandon_reg.otf")
format("opentype");
}
html, body {
padding:0;
margin: 0;
background-color:#222222;
}
body {
font-family:"Brandon Grotesque";
width: 1200px;
margin: 0 auto;
}
.container {
width: 1200px;
height:600px;
background-image:url("img/background.jpg");
text-align:center;
margin:auto;
padding:0;
}
Am I missing anything?
Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.
You could try "background-size: contain;" which will fit the entire image within the background area. If you do want to use "background-size: cover" you could add "background-position: center;" which will center the image within the background area.
The background-size property is used to set the background image size using CSS. Use height and width property to set the size of the background image.
You need to specify a few more properties for your background-image like this:
.container {
width: 1200px;
height:600px;
background-image: url("img/background.jpg");
background-size: cover; /* or contain depending on what you want */
background-position: center center;
background-repeat: no-repeat;
text-align:center;
margin:auto;
padding:0;
}
A detailed explanation of the background
property is available in the official MDN Web Docs.
This works fine!
background:rgb(37, 16, 13) url("images/bc02.jpg");
background-repeat: no-repeat;
width: 100%;
height:100%;
background-position: center center;
text-align:center;
margin:auto;
padding:0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With