【发布时间】:2016-06-14 20:30:48
【问题描述】:
我的网页中有带有背景图像、绝对位置和 -1 z-index 的 div,以便使图像静态并在这些图像上滚动 div 的其余部分。它在网络浏览器中完美运行,但我无法在手机中获得相同的功能。网络浏览器中的移动视图准确地显示了它应该工作的方式,但其他 div 不会在移动浏览器中滚动这些图像,而是与网络浏览器不同,图像也会滚动。
这是下面代码的JsFiddle link。
HTML
<div class="container">
<div class="section1">lorem ipsum dolar imit</div>
<div class="section3">
<div class="section3-img"></div>
</div>
<div class="section1">lorem ipsum dolar imit</div>
</div>
CSS
body{margin:0; padding:0;}
.container{height:800px; position:relative;}
.section1{
width:100%;
height:400px;
background-color:purple;
color:white;
z-index:10;
}
.section2, .section3{
width:100%;
height:300px;
overflow:hidden;
position:relative;
}
.section3-img{
background-size: cover;
z-index:-100;
width:100%;
height:300px;
position:absolute;
background:url('http://i.istockimg.com/file_thumbview_approve/81531733/6/stock-photo-81531733-texture-of-the-oak-stump-background.jpg') 0 top repeat fixed;
}
PS:我还在安卓手机的chrome浏览器上测试。
【问题讨论】:
-
Safari 手机不喜欢背景位置。见stackoverflow.com/questions/23236158/…
标签: css google-chrome mobile responsive-design css-position