固定背景未在Android上更新

时间:2015-03-06 00:21:30

标签: html css background

我在这里发现了类似的问题,但没有回答,但我找不到替代方案作为解决方案。

我有以下代码,它在Mac和Windows上运行完美,但我无法弄清楚为什么在Android(Chrome或Firefox)上,当用户向下滚动时背景不会更新,它会产生向下滚动时底部屏幕大约1/5的空间。 释放触摸后,背景图像会更新。

html{
  background-image:url(example.jpg);
  background-position:fixed;
  background-size:100% 100%;
}

1 个答案:

答案 0 :(得分:1)

指定html和body的高度,即

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

body    {
    height: 100%;
    min-height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
}

并添加一个div,将所有内容包裹在体内,即

<body>
    <div id="wrapmeup">
      ....your content....
    </div>
</body>

最后将此添加到您的css:

#wrapmeup {
    height: 100%;
    width: 100%;
    background-image: url(image/background.jpg);
    background-attachment: fixed;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
}