Nested stacking context using z-index
Hello guys, sorry to disturb you all; normally, when we have a nested stacking context, the child element shouldn't be always below the parent element stacking order even though it has a greater z-index?
In the uploaded picture, why is box3 (the box with the tomato-like color) stacked over its parent element, the blue-like color
5 Replies
It's the default behavior of a child to be in front of it's parent. Note that if you remove the z-index from all of the elements there is no change at all to the stacking order.
if I remove the z-index, even I remove the position property, then the stacking order is based on the document flow? The last element being defined will be above?
Hmmm I think in the video I watched, the child was always below its parent, I need to have a look
yep, the blue box will be in front by default because it's lower down in the html. And the red box will be infront of the pink because it is a child of the blue.
this is the article on z-index that made things click the most for me. In all honestly, must admit to having being pretty confused by z-index and stacking contexts for much longer than I'd like to admit. I think this is kind of a universal thing.
Jessica Chan
Coder Coder
4 reasons your z-index isn't working (and how to fix it) - Coder Coder
Z-index is one of those CSS properties that causes a ton of frustration due to some strange rules. Learn just how z-index works and avoid common pitfalls.
I will have a look, thanks !