gpt4 book ai didi

html - 在其::之前和::之后显示 Div?

转载 作者:搜寻专家 更新时间:2023-10-31 22:06:44 26 4
gpt4 key购买 nike

我试图在我的页面中使 div 显示在其 ::before::after CSS 选择器上,所以我正在努力获得这个结果:currently result

但我得到这个 JSFIDDLE what i want

这是我的代码:

HTML

<div class="box"></div>

CSS

.box{
width: 350px;
height: 350px;
background: #555;
position: absolute;
top: 50px;
left: 200px;
z-index: 10;
}
.box::before{
content: "";
background: #A60000;
width: 300px;
height: 300px;
position: absolute;
top: 25px;
left: -150px;
z-index: 1;
}
.box::after{
content: "";
background: #02047A;
width: 300px;
height: 300px;
position: absolute;
top: 25px;
left: 200px;
margin: auto;
z-index: 1;
}

我知道它看起来像是让 div 显示在其内容上,因为 Chrome 正在向我显示 HTML 源,如下所示:

enter image description here

但我希望有办法解决这个问题..

提前致谢...

最佳答案

更改您的 css 以遵循:

.box{
width: 350px;
height: 350px;
background: #555;
position: absolute;
top: 50px;
left: 200px;
}
.box::before{
content: "";
background: #A60000;
width: 300px;
height: 300px;
position: absolute;
top: 25px;
left: -150px;
z-index: -1;
}
.box::after{
content: "";
background: #02047A;
width: 300px;
height: 300px;
position: absolute;
top: 25px;
left: 200px;
margin: auto;
z-index: -1;
}

fiddle

您所要做的就是将 z-index :after:before 设置为 -1并从 .box z-index 中删除。

关于html - 在其::之前和::之后显示 Div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24193754/

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