gpt4 book ai didi

css - z-index 未按预期使用 before 伪元素呈现

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:34 24 4
gpt4 key购买 nike

为什么 #para1 不呈现 above #para1:before
<强> CODEPEN HERE

.para {
color: #fafafa;
}
#para1 {
background: blue;
padding: 0 0 20px 0;
position: relative;
z-index: 2;
}
#para1:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 0px;
height: 0px;
border: 150px solid rgba(0, 0, 0, 0);
border-top: 0px solid rgba(0, 0, 0, 0);
border-right: 50px solid rgba(0, 0, 0, 0);
border-left: 500px solid rgba(0, 0, 0, 0);
border-bottom-color: red;
z-index: 1;
display: block;
}
#para1 {
font-size: 40px;
}
<div id="para1" class="para"><span class="hpro">HELLO <span class="bold">WORLD</span> </span> <span class="satisfy">pre launch contest festival</span>
</div>

最佳答案

因为 #para 正在建立一个新的 stacking context本身。

尝试移除它的 z-index 并给它的伪 child 元素一个负的 z-index #para:before如下:

.para {
color: #fafafa;
}
#para1 {
background: blue;
padding: 0 0 20px 0;
position: relative;
/*z-index: 2;*/
}
#para1:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border: 150px solid rgba(0, 0, 0, 0);
border-top: 0 solid rgba(0, 0, 0, 0);
border-right: 50px solid rgba(0, 0, 0, 0);
border-left: 500px solid rgba(0, 0, 0, 0);
border-bottom-color: red;
z-index: -1;
}
#para1 {
font-size: 40px;
}
<div id="para1" class="para"><span class="hpro">HELLO <span class="bold">WORLD</span> </span> <span class="satisfy">pre launch contest festival</span>
</div>

关于css - z-index 未按预期使用 before 伪元素呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27667982/

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