new*_*man 5 html css html5 css3 twitter-bootstrap-3
我在浏览器上放大容器的背景图像时出现问题.画面很1200px
宽,我的容器也1200px
很宽.我把它设置为我的.container选择器的背景图像.当我在浏览器中加载它时,它只显示图像的一小部分,因为它到目前为止已放大.为什么会这样?
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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
您需要为背景图像指定更多属性,如下所示:
.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;
}
Run Code Online (Sandbox Code Playgroud)