CSS z-index Manager and Stacking Context Map
Paste CSS to list every z-index with its problems, define named layers and export them as CSS variables or tokens, and model nested contexts.
Berjalan dalam pelayar anda. Fail anda tidak pernah meninggalkan peranti. Lihat cara menyemaknya
…
Cara melakukannya
- 1Paste your CSS
Open the conflict finder and paste the stylesheet or the suspicious rules.
- 2Read each z-index
Check the notes for missing position, magic numbers and context creators.
- 3Define layers
In the named scale tab, rename and renumber layers for your product.
- 4Export tokens
Choose CSS variables, SCSS, JSON, Tailwind or TypeScript and copy.
- 5Rewrite with tokens
Copy the CSS rewritten with var() references and review it.
- 6Model the tree
Add components in the stacking map to see the real paint order.
Tentang alat ini
Most z-index bugs are not about the number. A dropdown with z-index 9999 still disappears behind a sticky header with z-index 10 when the dropdown sits inside a parent that forms its own stacking context, because a child can never rise above the siblings of that context. Many properties create a context without anyone noticing: opacity below 1, any transform, filter, will-change, isolation, mix-blend-mode, contain and position fixed or sticky. Over time a codebase collects random values like 2, 10, 99, 1000 and 99999 that nobody dares to touch. This manager attacks the problem from three sides: a conflict finder that reads your CSS and explains each z-index, a named scale that replaces magic numbers with layers such as dropdown, sticky, modal and tooltip, and a stacking map where you model your component tree and see the order in which the browser will actually paint it.
Conflict finder
Paste CSS (plain CSS, or SCSS and Less without nesting). Every rule that sets z-index is listed with its line, selector and value. CSS variables are resolved when they are defined in the same paste or belong to the scale. For each rule the tool reports what else in that rule creates a stacking context and the usual mistakes: no position in the rule (z-index works only on positioned elements and on flex or grid items), position static, values of 9999 and above, numbers that are not in your scale, undefined variables, and negative values that may slide behind a parent's background. Values shared by different selectors are grouped, because when those components overlap the later one in the DOM wins, which is rarely what anyone intended.
Named scale
A starting scale covers below, base, raised, dropdown, sticky, fixed, overlay, modal, popover, toast and tooltip, spaced in hundreds from 1000 so that a new layer fits in later. Rename, renumber, add notes and remove layers; the tool warns when two layers share a value. Export the scale as CSS custom properties, SCSS variables with a map, a design-tokens JSON file, a Tailwind theme extension or a TypeScript constant. The conflict tab can then rewrite your pasted CSS to use var(--z-name) for the nearest layer of every raw number, as a starting point for a clean-up pull request.
Stacking map
Add components with a parent, a z-index (blank for auto), their order in the DOM and whether another property makes them a stacking context. The map computes paint order from bottom to top using the CSS 2.1 rules: inside each context, negative values first, then auto and zero in tree order, then positive values; nested contexts are painted as a unit. Each entry shows its full path, which makes it obvious why a high number inside a low context loses. A simple stacked preview draws the same order with coloured cards.
Limits
The finder reads CSS text and cannot see which elements overlap on screen, inline styles set by JavaScript or the DOM structure, so it does not prove that a conflict is visible. The stacking map is a model you build, not a scan of your page, and it ignores the separate painting of floats, inline content and the top layer used by dialog and popover elements.
Contoh berselesaian
A team's sample CSS has eight z-index rules. The finder shows the dropdown menu at 9999, the toast and the modal both at 1050, a hover rule at 2 without any position, and a hero at 1 that also has transform. In the stacking map, the header (100) contains the dropdown (9999) and the modal sits at the root with 1050. The paint order reads main, hero, header, dropdown, modal: the dropdown can never cover the modal, and it would also lose to any root sibling above 100. The team exports the scale as CSS variables, accepts the rewrite to var(--z-dropdown), var(--z-modal) and var(--z-toast), and the duplicate 1050 problem disappears because toast now has 1600.
Ringkasnya
- Kategori: Pembangun & data
- Berjalan dalam pelayar, tanpa pendaftaran, tanpa muat naik.
- Maklumat yang anda masukkan kekal pada peranti anda.
- Tersedia dalam bahasa Inggeris.
- Kandungan disemak kali terakhir:
- Sumber rasmi: W3C CSS 2.1 Appendix E (stacking order) and CSS Positioned Layout Level 3
Soalan lazim
Why does my z-index 9999 not work?
Usually because an ancestor creates a stacking context with a lower value. The element is then compared only with elements inside that ancestor. Check the ancestors for transform, opacity, filter or a z-index of their own.
Does z-index need position?
It needs a positioned element (relative, absolute, fixed or sticky) or a flex or grid item. On a static block element it is ignored.
What is a good z-index scale?
A short list of named layers with gaps, for example 1000 for dropdowns up to 1700 for tooltips. Components use the names, never raw numbers.
What does isolation: isolate do?
It creates a stacking context without changing anything else. It is the clean way to keep a component's internal z-index values from leaking out.
Can the tool fix my CSS automatically?
It writes a version where each number is replaced by the nearest layer variable. Review it before merging, because the nearest layer is a guess.
Where is my data kept?
In this browser only. The scale, pasted CSS and stacking map are stored as a local draft with undo and redo.
