Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 带有固定背景附件的粘性元素_Html_Css - Fatal编程技术网

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上面,不知道这是否是你想要的