gpt4 book ai didi

css - 绝对和静态定位元素元素上的 z-index

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

如何让绝对定位元素出现在静态元素下。

Z-index 似乎不起作用。绿色框应该在线上方(将为白色)。

http://jsfiddle.net/matthewabrman/pbL52gtj/

html:

<h3 class="line"><span>Lorem Ipsum</span></h3>

CSS:

h3.line {
font-size: 24px;
display: block;
font-weight: 300;
text-align: center;
margin:30px;
position: relative;
}

h3.line:after {
content: '';
position: absolute;
left: 0;
top: 15px;
width: 100%;
height: 1px;
background-color: #e0e0e0;
}

h3.line > span {
background-color: #afa;
padding: 10px 20px;
}

最佳答案

试试这个。希望你正在尝试得到这个 FIDDLE

h3.line {
font-size: 24px;
display: block;
font-weight: 300;
text-align: center;
margin:30px;
position: relative;
z-index:-1;
}

h3.line:after {
content: '';
position: absolute;
left: 0;
top: 15px;
width: 100%;
height: 1px;
background-color: #e0e0e0;
}

h3.line > span {
background-color: #afa;
padding: 10px 20px;
position: relative;
z-index:1;
}

FIDDLE

h3.line {
font-size: 24px;
display: block;
font-weight: 300;
text-align: center;
margin:30px;
position: relative;

}

h3.line:after {
content: '';
position: absolute;
left: 0;
top: 15px;
width: 100%;
height: 1px;
background-color: #e0e0e0;
z-index:-1;
}

h3.line > span {
background-color: #afa;
padding: 10px 20px;
}

关于css - 绝对和静态定位元素元素上的 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25176552/

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