Here is a behavior that I donβt quite understand regarding the z-index and css of the :: before / :: after pseudo-element.
This is illustrated on this jsfiddle: http://jsfiddle.net/jgoyon/T6QCf/
I created a placed box and added the contents with :: after the pseudo-element (also positioned).
- if I set the z-index for the after after element, everything works fine, and I can position it above the parent or under the parent, playing with z-index
#no-z-index { background:lightblue; width:100px; height:100px; position:relative; } #no-z-index:after { content: 'z-index -1'; width:50px; height:50px; background:yellow; position:absolute; z-index:-1; top:70px; left:70px; }
- If I do the same and set the z-index of the parent, it no longer works.
#z-index { background:lightblue; left:200px; width:100px; height:100px; position:relative; z-index:0; } #z-index:after { content: 'z-index -1'; width:50px; height:50px; background:yellow; position:absolute; z-index:-1; top:70px; left:70px; }
Is this expected behavior?
source share