z-index: -1
时,:before
的 z-index:2
不起作用。
如何将:before
移动到框下方,同时保持框z-index:2
。
.box{
background: lavender;
height: 200px;
width: 200px;
position: absolute;
left: 50%;
transform: translateX(-50%);
z-index: 2;
}
.box:before{
content: '';
width: 100%;
height: 100%;
border: 1px solid #000;
position: absolute;
right: -20px;
bottom: -20px;
z-index: -1;
}
<div class="box">
</div>