Html 带有固定背景附件的粘性元素
考虑这一点: 示例代码:Html 带有固定背景附件的粘性元素,html,css,Html,Css,考虑这一点: 示例代码: <div class="first"><img src="http://placekitten.com/g/200/300"/></div> <div class="second"></div> <div class="third"></div> .first { background-color: #a6a6a6; height: 600px; background-attachme
<div class="first"><img src="http://placekitten.com/g/200/300"/></div>
<div class="second"></div>
<div class="third"></div>
.first {
background-color: #a6a6a6;
height: 600px;
background-attachment: fixed;
background-image: url("http://placehold.it/1000x500");
}
.second {
background-color: #fff;
min-height: 500px;
}
.third {
background-color: #ff0000;
min-height: 500px;
background-attachment: fixed;
}
.首先{
背景色:#A6;
高度:600px;
背景附件:固定;
背景图像:url(“http://placehold.it/1000x500");
}
.第二{
背景色:#fff;
最小高度:500px;
}
.第三{
背景色:#ff0000;
最小高度:500px;
背景附件:固定;
}
我希望cat图片保持粘性,以便第二个div('.second')可以像覆盖背景一样覆盖它
我想模拟与背景附件相同的行为:用猫图片修复
帮助。在图像上,使用
位置:fixed
防止其滚动,并使用z-index:-1
使其位于事物后面
如果它在你不想要的东西后面,用z-index:-2在它上面你只是在寻找像这样简单的东西:
img{position:fixed;}
试过了,但是猫在第二个div上面,不知道这是否是你想要的