Okay so I have this test setup in my html
<div style="position:absolute;left:0px;top:0px;z-index:1;width:200px;height:200px;background-color:red;">
<div style="position:absolute;left:0px;top:0px;z-index:3;width:50px;height:50px;background-color:green;"></div>
</div>
<div style="position:absolute;left:0px;top:0px;z-index:2;width:100px;height:100px;background-color:blue"></div>
Where the I want the blue div to render in front of the red div, but I want the child div(green) of red to render in front of blue, looking at that code it seems it should work if z-index was global, but it seems to be local to the parent element, as the blue render above red, but the green doesn't render on top unless I move the green div up out of the parent? How can I use "global z-indexes" or whatever it is. It is vital to my actual project that it works this way
The z-index of elements inside of a stacking context are always relative to the parent's current order in its own stacking context.
You can change the z-index of any child elements all you want, but that won't do anything! The z-value of each of these elements is 6, and there's no way to change that without modifying the z-index of #parent. In technical terms, a stacking context is formed when a positioned element has a z-index.
No, it isn't inherited.
This is impossible as a child's z-index is set to the same stacking index as its parent.
Z-indices are always local, or relative, to the closest positioned ancestor (in this case the parent). There is no global z-index
property in CSS.
You will have to move the green div
out of its parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With