我希望实现我网页的某些部分,以使背景图像能够完整地展开页面,边缘没有空白区域。这可能吗?我使用基础5框架。
HTML
<div class="row" id="wrapper">
<div class="large-12 columns">
<div class="kickstart"><img src="img/kick-start.png">
<p class="getfit"><img src="img/get-fit.png"></p>
<p class="home-text"> BodyMetrix Personal Training is a new company, based in South London, aiming to bring one-on-one training sessions and personalised exercise and nutrition plans. </p>
<p class="get-contact"><img src="img/get-contact-btn.png"></p>
</div>
</div>
</div>
CSS
#wrapper {
background-image: url("../img/home-img.png");
background-repeat: no-repeat;
width: 100% !important;
z-index: 0;
}
.kickstart {
padding: 30px;
}
.getfit {
padding-top: 10px;
}
.home-text {
font-family: 'Open Sans', sans-serif;
font-size: 1em;
font-weight: normal;
color: black;
}
答案 0 :(得分:5)
有两种方法可以做到这一点。
您可以#wrapper
宽100%
,或将HTML更改为:
<div id="wrapper">
<div class="row">
<div class="large-12 columns">
<div class="kickstart"><img src="img/kick-start.png">
<p class="getfit"><img src="img/get-fit.png"></p>
<p class="home-text"> BodyMetrix Personal Training is a new company, based in South London, aiming to bring one-on-one training sessions and personalised exercise and nutrition plans. </p>
<p class="get-contact"><img src="img/get-contact-btn.png"></p>
</div>
</div>
</div>
</div>
由于div
是一个块元素,因此默认情况下会width:100%
。只要它不在现有的.row
类中,它就是100%
。
答案 1 :(得分:2)
#wrapper {
background-image: url("../img/home-img.png");
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
width: 100% !important;
z-index: 0;
}
答案 2 :(得分:-1)
您可以使用background-size属性调整背景大小。在你的情况下,你希望它覆盖整个屏幕
请尝试以下代码:
#wrapper {
background: url("../img/home-img.png") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width: 100% !important;
z-index: 0;
}