gpt4 book ai didi

html - Z-Index 不适用于 :after

转载 作者:行者123 更新时间:2023-11-28 16:19:52 25 4
gpt4 key购买 nike

我正在尝试让 h1.logo 与 header:after 重叠。

我尝试按照我看到的建议添加一个相对于具有正 z-index 的 body 的位置,但我在这里不这样做。

有没有办法让 z-index 起作用?

这是我的代码css

body {
position: relative;
z-index: 100;
}
header {
background: #184677;
width: 100%;
height: 55px;
position: relative;
}
header:after {
content:"";
display:block;
position:absolute;
z-index:0;
left:0px;
right:0px;
bottom:-8px; border-bottom:4px solid #184677;
}
a {
text-decoration: none;
color: #eee;
}
h1.logo {
display: inline;
float: left;
margin: 0 0 0 13%;
padding: 15px;
background: green;
border-radius: 0 0 3px 3px;
z-index: 100;
}

这是html

<header>
<h1 class="logo"><a href="#">Test</a></h1>
</header>

最佳答案

只需在 header:after 上使用 z-index: -1;

body {
position: relative;
z-index: 100;
}
header {
background: #184677;
width: 100%;
height: 55px;
position: relative;
}
header:after {
content:"";
display:block;
position:absolute;
z-index:-1; /* -1 instead of 0 */
left:0px;
right:0px;
bottom:-8px; border-bottom:4px solid #184677;
}
a {
text-decoration: none;
color: #eee;
}
h1.logo {
display: inline;
float: left;
margin: 0 0 0 13%;
padding: 15px;
background: green;
border-radius: 0 0 3px 3px;
z-index: 100;
}
<header>
<h1 class="logo"><a href="#">Test</a></h1>
</header>

关于html - Z-Index 不适用于 :after,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37038423/

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