Set the z-index
of the :before
or :after
pseudo element to -1 and give it a position
that honors the z-index
property (absolute
, relative
, or fixed
). This works because the pseudo element's z-index
is relative to its parent element, rather than <html>
, which is the default for other elements. Which makes sense because they are child elements of <html>
.
The problem I was having (that lead me to this question and the accepted answer above) was that I was trying to use a :after
pseudo element to get fancy with a background to an element with z-index
of 15, and even when set with a z-index
of 14, it was still being rendered on top of its parent. This is because, in that stacking context, it's parent has a z-index
of 0.
Hopefully that helps clarify a little what's going on.