Why does z-index only work on positioned elements?
Z-index only affects elements that create or belong to a stacking context, which requires position other than static. Without positioning, z-index is ignored visually.
💡 Only positioned elements respond to z-index layering (see step 2 and 3).
Why can’t a child with higher z-index appear above a parent’s sibling with lower z-index?
Because stacking contexts isolate children. A child’s z-index is relative only inside its stacking context, so it can’t escape to appear above elements in a different stacking context.
💡 Stacking contexts act like separate layers; children can’t jump outside (see step 5).
Why does opacity less than 1 create a stacking context?
Opacity less than 1 creates a new stacking context so the browser can composite the semi-transparent element separately, ensuring correct blending and layering.
💡 Transparency triggers stacking context to isolate effects.