13

在我的页面中有 2-3 个部分具有 100% 的宽度和背景。当我全屏打开它时一切正常,但是当屏幕小于 960 像素(本节内容的宽度)时,背景图像不是整个页面。右边的 whis 隐藏在第一刻没有背景 - 它是白色的。你可以在这里看到我的意思:http: //micobg.net/10th/

4

3 回答 3

24

只需将background-size:100%样式添加到您应用的元素background-image。适用于 Firefox、Safari 和 Opera。例如:

<style>
.divWithBgImage {
  width: 100%;
  height: 600px;
  background-image: url(image.jpg);
  background-repeat: no-repeat;
  background-size: 100%; //propotional resize
/*
  background-size: 100% 100%; //stretch resize
*/
}
</style>
<div class="divWithBgImage">
  some contents
</div>
于 2012-08-24T12:33:17.400 回答
5

关于这篇文章,你也应该使用cover

html { 
  background: url(PATH_TO_IMAGE) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
于 2016-05-17T19:15:04.993 回答
2

使用背景最小宽度:960px;而不是宽度:100%;干杯

于 2012-08-23T14:08:59.270 回答