整页背景图片

时间:2014-04-11 10:04:53

标签: html css css3

我一直在尝试获得整页背景图片。我怎么能得到这个背景图像来占用页面的高度而不必滚动?

http://jsfiddle.net/DFN5y/

#cover {
 background: url(http://bootstrapguru.com/preview/cascade/images/carousel/imageOne.jpg) no-repeat center center fixed; 
 background-size: cover;
 height:100%;
}

目前100%加上固定高度使它太高了。

2 个答案:

答案 0 :(得分:2)

#cover提供固定的位置和流畅的尺寸:

#cover {
    background: url(http://bootstrapguru.com/preview/cascade/images/carousel/imageOne.jpg) no-repeat center center fixed; 
    background-size: cover;
    height:100%;
    width: 100%;
    position:fixed;
}

Working demo

答案 1 :(得分:1)

你可以为身体做样式:

body {
  background: url(http://bootstrapguru.com/preview/cascade/images/carousel/imageOne.jpg) no-repeat center center fixed; 
 background-size: cover;
}

<强> Working Demo

更新,没有样式正文

 #cover {
   background: url(http://bootstrapguru.com/preview/cascade/images/carousel/imageOne.jpg) no-repeat center center fixed; 
   background-size: cover;
   height:100%;
   position:fixed;
   width: 100%;
   }

<强> Working Demo