CSS3 & Modern Layouts (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is a Stacking Context and why does `z-index: 99999` sometimes fail?
senior LevelMost AskedMemory ManagementSystem DesignData Structures
In Simple Words:
z-index only controls stacking order within the same Stacking Context.
An element with z-index: 99999 will still render behind an element with z-index: 1 if its parent container is trapped in a lower stacking context!
What Creates a New Stacking Context:
- Root element (
<html>). - Positioned elements (
relative,absolute,fixed,sticky) withz-indexother thanauto. - Elements with
opacityless than1. - Elements with
transform,filter,perspective, orclip-path. - Elements with
isolation: isolate(The modern, clean way to contain stacking contexts!). - Elements with
container-type.