位置固定背景高度100%

时间:2013-04-14 19:21:38

标签: html css

我的页面需要一个背景。我怎么解决这个问题。问题是不使用position: fixed如果我的内容增长,背景将不可见。

<body>
   <div id="Bgr"></div>
   ...
</body>

#Bgr
{
  position: fixed;
  height: 100%;
  background: url('../images/content-background.png') repeat-y 0, 0;
}

更新:我已经在身体和我的html中有不同的背景,身体是100%身高

3 个答案:

答案 0 :(得分:1)

确保正文CSS是窗口大小。常见的是忽视。

添加

body {
    width:100%;
    height:100%;
}

答案 1 :(得分:0)

我可以将这两个图像放入正文,因为IE10等也解决了我的问题。

答案 2 :(得分:0)

我喜欢使用absolute来做这件事:

#Bgr
{
    position: absolute;
    background: url('../images/content-background.png') repeat-y 0, 0;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
}