Category:
css
Trouble with z-indexing pseudo elements.
Pseudo elements are great little things, they can help you make nice little graphical feathers without writing extra markup, or they can provide description elements putting url(), attr(), counter() into content property.
But when making flags or some similar extra graphical feathers, pseudo class element seems to have larger z-index then his parent element, which defeats the purpose, so this is how you make it better :)
- Parent element must have z-index set.
- Pseudo patent element must not have defined z-index
- Pseudo element must have z-index set to negative value
#parent { position: relative; width: 200px; height: 200px; z-index: 1; background-color: blue; margin-left:35%; } #pseudo-parent { position: absolute; } #pseudo-parent:after { content: ""; width: 100px; height: 100px; display: block; position: absolute; z-index: -1; background-color: red; top:0; left:-25px; }
One thought on “Trouble with z-indexing pseudo elements.”
April 11, 2017 at 13:22
Thanks man!!! really!!