0
我有一个元素有两个伪元素,:before
和:after
。父母的位置与z-index: 0
相关,两个伪元素的绝对位置为z-index: -1
。顶部伪元素的堆栈顶部
但是,我无法获得顶层的父元素。我怎样才能解决这个问题?
下面是说明这一问题的codepen:http://codepen.io/zthall/pen/NNmKgZ
的SCSS代码:
.pokeball {
height: $size/5;
width: $size/5;
background: white;
border-radius: 50%;
border: ($size/20) solid $black;
position: relative;
margin: ($size * 4/5);
z-index: 1;
&:after,
&:before {
content: '';
display: block;
width: $size;
height: $size/2;
border-radius: $size $size 0 0;
border: ($size/20) solid $black;
z-index: -1;
position: absolute;
}
&:after {
background: $red;
top: -$size/2;
left: -$size/2;
}
&:before {
background: $white;
top: 0;
left: -$size/2;
transform: rotate(180deg);
}
}
的HTML:
<div class="pokeball"></div>
'的z-index:0'让家长建立堆叠环境,然后这是不可能的。只要删除它。可能的[CSS:在父元素后面](http://stackoverflow.com/q/34190157/1529630)或[HTML:获取要显示的子元素(较低的z-index)比其父元素?](http ://stackoverflow.com/q/2503705/1529630) – Oriol
谢谢,@Oriol。有趣的是,现在它只是在动画中消失。 – Zack