gpt4 book ai didi

css - z-index 不适用于::after/::before 元素?

转载 作者:技术小花猫 更新时间:2023-10-29 11:56:01 24 4
gpt4 key购买 nike

z-index 不适用于其 ::before/::after 元素。我在下面分享代码。

.or {
border: 2px solid #8fc300;
border-radius: 5px;
color: #333;
font-size: 17px;
font-weight: 600;
height: 34px;
line-height: 26px;
text-align: center;
width: 34px;
margin-top: 64px;
margin-left: 20px;
margin-right: 20px;
background: #fff;
/*For z-index - keep the green area on top*/
position: relative;
z-index: 11;
}
.or::after {
background: red;
content: "";
display: block;
height: 116px;
margin-left: 15px;
margin-top: -68px;
width: 4px;
/*For z-index - keep the green area on top*/
position: relative;
z-index: 9;
}
<div class="or"></div>

最佳答案

您可以从父元素中删除 z-index 并在伪元素上使用负值 z-index: -1。如果你只想要红线上的绿线,你还需要从父级中删除白色背景 DEMO

.or {
border: 2px solid #8fc300;
border-radius: 5px;
color: #333;
font-size: 17px;
font-weight: 600;
height: 34px;
line-height: 26px;
text-align: center;
width: 34px;
margin-top: 64px;
margin-left: 20px;
margin-right: 20px;
background: #fff;
/*For z-index - keep the green area on top*/
position: relative;
}
.or::after {
background: red;
content: "";
display: block;
height: 116px;
margin-left: 15px;
margin-top: -68px;
width: 4px;
/*For z-index - keep the green area on top*/
position: absolute;
z-index: -1;
}
<div class="or"></div>

关于css - z-index 不适用于::after/::before 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39489738/

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