我正在尝试让我的背景图像适合 100% 的屏幕宽度和高度。但它甚至没有显示我的形象。任何可以告诉我我做错了什么的人。
在这里您可以看到我已经尝试过的代码。我不明白为什么它不起作用。
<section id="forside" >
<div class="container">
<div class="row">
</div>
</div>
</section>
#forside {
background: url(images/FBIlled.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
我的形象甚至没有得到展示。它只是空白。我希望带有 id="forside"的部分的图像 FBIlled 为 100% 屏幕宽度和高度。完整代码可以在这里显示:https://codepen.io/anon/pen/maLYrZ
最佳答案
更好的主意:
body, html {
margin: 0;
height: 100%;
}
.bg {
/* The image used */
background-image: url("img_girl.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<div class="bg"></div>
将代码放在 div 中。
取自https://www.w3schools.com/howto/howto_css_full_page.asp .
关于html - 为什么我的图像不适合 100% 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54077571/