CSS
css/z-index-scale
z-index values come from a named scale (custom properties or Sass variables), not ad hoc numbers such as 999 or 9999.
drobnastatycznefe-css-architecture
Dlaczego
Ad hoc numbers escalate: a dropdown gets 100, a modal 999, a toast 9999, and the next fix needs 99999. Nobody can tell which layer should win, and a higher number does not even help when the element sits in a different stacking context.
Poprawka
Define the layers once, in order, and use the names: --z-dropdown: 1000; --z-modal: 1100; --z-toast: 1200; (or a Sass map). Inside a component keep small local values (below 10) and create a stacking context with isolation: isolate instead of raising the number. When the project already has a scale, the fix names it.
Przykłady
/* bad */
.modal { z-index: 9999; }
/* good */
:root { --z-dropdown: 1000; --z-modal: 1100; --z-toast: 1200; }
.modal { z-index: var(--z-modal); }Źródła
Fakty
- Identyfikator
css/z-index-scale- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
project- Uczy jej skill
fe-css-architectureCSS architecture and tokens- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain css/z-index-scale