Reputation: 2800
I am trying to sandwich an element between ':before' and ':after' pseudo elements, however despite setting z-index to -1 on the ':after' it still appears on top of the parent.
In the following example red should be on top, green in the middle, blue on the bottom.
See this fiddle: https://jsfiddle.net/zL1yz86f/2/
HTML:
<div></div>
CSS:
div {
background: green;
position: relative;
z-index: 10;
width: 30%;
height: 200px;
float: left;
margin-right: 3%}
div:before {
content: "";
height: 0;
width: 0;
border-top: 200px solid red;
border-right: 200px solid transparent;
position: absolute;
top: -20px;
left: -10px;
z-index: 20;
}
div:after {
content: "";
height: 200px;
width: 200px;
background: blue;
position: absolute;
top: -20px;
left: -10px;
z-index: -1;
}
Upvotes: 0
Views: 615