gpt4 book ai didi

html - z-index 不适用于相对父元素和之后/之前元素

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

我有这样的代码(原型(prototype)):

.headerz {
position: relative;
padding: 5rem 0 0 5rem;
margin: 3rem 0 0 0;
color: #000;
font-size: 3.8rem;
text-transform: uppercase;
z-index: 24;
}

.headerz::before {
content: "";
position: absolute;
width: 110px;
height: 100px;
left: 0;
bottom: -3rem;
background-color: red;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
z-index: 22;
}

.headerz::after {
content: "";
position: absolute;
width: 72px;
height: 66px;
left: 8.5rem;
top: -2.8rem;
background-color: blue;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
z-index: 22;
}
<h3 class="headerz">Contacts</h3>

https://codepen.io/anon/pen/LrLjqQ

为什么我的红色方 block 不在文字下方?

最佳答案

在 before 元素上添加 z-index: -1

.footer-contacts-header-main {
position: relative;
padding: 5rem 0 0 5rem;
margin: 3rem 0 0 0;
color: #000;
font-size: 3.8rem;
text-transform: uppercase;
z-index: 24;
}

.footer-contacts-header-main::before {
content: "";
position: absolute;
width: 110px;
height: 100px;
left: 0;
bottom: -3rem;
background-color: red;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
z-index: -1;
}

.footer-contacts-header-main::after {
content: "";
position: absolute;
width: 72px;
height: 66px;
left: 8.5rem;
top: -2.8rem;
background-color: blue;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
z-index: 22;
}
<h3 class="footer-contacts-header-main">Contacts</h3>

关于html - z-index 不适用于相对父元素和之后/之前元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50837760/

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