The problem is that the two pseudo-elements are stacked as if they were child elements of .left-table
, and as such, they form a stacking context that is considered to be part of the stacking order of their parent block, that is, .left-table
.
You need to create a background masking element that is a child of .left-table
and then
positioning it absolutely within .left-table
.
When you do this, then the z-index
can be used to stack the green rectangle behind the red and
black elements.
Read more about how stacking order works: http://www.w3.org/TR/CSS21/zindex.html#stacking-defs
Note: It was not clear to me what the transforms were trying to do so I left them out since
they were not relevant to the issue of the stacking order.
.left_table{
position:absolute;
top:0px;
left: 0;
width:250px;
height:175px;
}
.inner-mask {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: #000;
}
.left_table:before{
content:'';
position:absolute;
background-color: red;
bottom:-28px;
width:250px;
height:30px;
}
.left_table:after{
content:'';
position:absolute;
background-color: green;
right:30px;
width:15px;
height:250px;
z-index: -1;
}
<div class="left_table">
<div class="inner-mask"></div>
</div>