Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my container background image so zoomed in?

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?

like image 528
newman Avatar asked Apr 05 '15 23:04

newman


People also ask

How do I make the background image fit my screen size?

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.

How do you Unzoom a background image in CSS?

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.

How do I resize a background image in CSS?

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.


2 Answers

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.

like image 89
AndrewL64 Avatar answered Nov 01 '22 09:11

AndrewL64


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;
like image 41
ganji Avatar answered Nov 01 '22 10:11

ganji