此问题在此处已有答案:
Why can't an element with a z-index value cover its child?(4个答案)
10天前关门了。
我想把::after
元素移到parent
div下面,但是效果不太好。如何把绿色框移到蓝色下?
.parent {
height: 100px;
width: 100px;
background: blue;
position: relative;
z-index: 10;
}
.parent::after {
position: absolute;
top: -10px;
background: green;
content: '';
height: 40px;
width: 40px;
z-index: 2;
}
个字符
1条答案
按热度按时间v1uwarro1#
因为你在
.parent
上有position: relative
。你可以添加一个.container
并将position: relative
移动到它。个字符