A nested 10 does not beat a sibling context of 2
.one { position: relative; z-index: 1; }
.two { position: relative; z-index: 2; }
.one .high { position: relative; z-index: 10; }The 10 is compared only inside the z-index: 1 context. It cannot outrank the sibling context whose z-index is 2.
- This is the stacking-context rule, not a measured paint order from a browser.
<section class="parent one">
<div class="high">z-index 10 inside 1</div>
</section>
<section class="parent two">
<div class="plain">sibling context 2</div>
</section>
<style>
.parent { position: relative; width: 16rem; font-family: sans-serif; background: #F3EFE4; border: 1px solid #0B5853; }
.one { z-index: 1; }
.two { z-index: 2; }
.high { position: relative; z-index: 10; }
</style>What this markup means
Both sections are positioned, so their z-index values create two stacking contexts, 1 and 2. The nested .high has z-index: 10, but that 10 is local to .one. Painting .two above .one still paints all of .one, including .high, below .two. Increasing the nested number does not change that. isolation: isolate would also form a context, still without making its descendants globally comparable.
Related: Position (z-index trigger), Display