【发布时间】:2014-06-12 20:56:06
【问题描述】:
我正在尝试在我的页面中使 div 显示在其 ::before 和 ::after CSS 选择器上,所以我正在努力获得这个结果:
但我收到了这个JSFIDDLE
这是我的代码:
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 源代码,如下所示:
但我希望有办法解决这个问题..
提前致谢...
【问题讨论】:
-
将子元素发送到其父元素后面的唯一方法是使用 negative z-index。
标签: html css pseudo-element