为什么我的背景图像如此放大? [英] Why is my background image so zoomed in?

查看:141
本文介绍了为什么我的背景图像如此放大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是一个非常基本的问题,但是我在浏览器中放大容器的背景图像时遇到问题。图片宽1200px,容器宽1200px。我将它设置为我的.container选择器的背景图像。当我在浏览器中加载时,它只显示图像的一小部分,因为它放大到目前为止......这是否有意义?也许它更容易解释我的代码....

Sorry if this is a very elementary question, but 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...does this make sense?Maybe its easier to explain with my code....

HTML:

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:

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? Thanks guys!

推荐答案

您需要为您的背景图像指定更多属性,如下所示:

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;
}

这篇关于为什么我的背景图像如此放大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆