全宽度背景图片 - Foundation

6
我希望我的网页的某些部分拥有一张铺满整个页面的背景图片,边缘没有任何白色空间。这是否可能?我正在使用Foundation 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;
}

可能是Stretch background image css?的重复问题。 - Godwin
3个回答

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%

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接