I have an element with two pseudo elements, :before
and :after
. The parent is positioned relative with z-index: 0
, and the two pseudo elements are positioned absolute with z-index: -1
.
However, I can't get the parent element to stack on top. How can I fix this?
Here's a codepen illustrating the issue: http://codepen.io/zthall/pen/NNmKgZ
The SCSS code:
.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);
}
}
The HTML:
<div class="pokeball"></div>