gpt4 book ai didi

css - 绝对 :position and z-index:1 element 之前/之后

转载 作者:行者123 更新时间:2023-11-28 17:26:08 25 4
gpt4 key购买 nike

如何在 position: absolute 元素下安排 :before 或 :after 伪元素 position: absolutez-index: -1 > 和 z-index: 1

https://jsfiddle.net/x5x6ye97/2/

#element { 
position: absolute;
z-index: 1;

width: 100px;
height: 100px;
background-color: blue;
}

#element::after {
content: "";
width: 150px;
height: 150px;
background-color: red;
position: absolute;
top: 20px;
z-index: -1;
}
<div id="element"></div>

最佳答案

嗯,我想你想实现这个...

下面是工作代码-

#element { 
position: relative; /* optional */
width: 100px;
height: 100px;
background-color: green;
}

#element::after {
content: "";
width: 150px;
height: 150px;
background-color: yellow;
position: absolute;
z-index: -1;
}
<div id="element"></div>

希望这对您有所帮助:)

关于css - 绝对 :position and z-index:1 element 之前/之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39895733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com