CSS Nesting
Annidamento CSS
L'annidamento CSS è una sintassi integrata per scrivere una regola di stile dentro un'altra. Il browser segue comunque le regole CSS per la lettura dei selettori e della loro specificità.
Un altro esempio
Un pulsante nidifica `&:hover`, `&:focus-visible` e `@media (forced-colors: active)` all'interno di `.button`. Questo mantiene sei regole di stato vicino alla regola base. Una revisione rifiuta tre livelli di selettori figli perché legherebbero il pulsante a una sola struttura di pagina.
Parti principali
- 01Regola di stile del genitore
- 02selettore annidato o regola `at`
- 03selettore risolto
Usalo quando
Usa uno o due livelli superficiali per stati, versioni e regole condizionali @-rules che appartengono allo stesso componente.
Non usarlo quando
Evitare catene profonde di elementi figli e legami nascosti con la struttura DOM esatta. L'annidamento nativo non si comporta sempre come un preprocessore CSS.
Nome usato nel codice
nested style rules with &, relative selectors, and nested group rules Prima di spedire
Check content order, shared design values, component consistency, contrast, zoom, and layout changes by screen size. Verify every theme, language, and state. If there is motion, offer an equal reduced-motion experience.
Outcome: Complete the task with Annidamento CSS (CSS Nesting). User context: Un pulsante nidifica `&:hover`, `&:focus-visible` e `@media (forced-colors: active)` all'interno di `.button`. Questo mantiene sei regole di stato vicino alla regola base. Una revisione rifiuta tre livelli di selettori figli perché legherebbero il pulsante a una sola struttura di pagina. Design concept to apply: Annidamento CSS (CSS Nesting). Why it fits: Usa uno o due livelli superficiali per stati, versioni e regole condizionali @-rules che appartengono allo stesso componente. Do not use it when: Evitare catene profonde di elementi figli e legami nascosti con la struttura DOM esatta. L'annidamento nativo non si comporta sempre come un preprocessore CSS. Design requirements: Set the content order, shared design values, and reusable components. Define how the layout changes by screen size and state. Keep useful design choices separate from decoration. Inclusion and resilience: Check contrast, zoom, languages, themes, and reduced motion when needed. Do not use color or effects as the only way to show meaning. Acceptance criteria: The design stays clear on phones and desktops, at zoom, in every theme, and in all supported languages. Interactive states stay clear and consistent. Evidence and limits (evidence boundary): Un documento formale può ancora essere una bozza, un release candidate o la versione finale. Controlla il suo stato e il supporto per browser o piattaforma. Unknowns to confirm: Brand limits, amount of content, supported themes and languages, target devices, and design-system rules.
Controlla questa richiesta
Review how Annidamento CSS (CSS Nesting) is used now. Definition: L'annidamento CSS è una sintassi integrata per scrivere una regola di stile dentro un'altra. Il browser segue comunque le regole CSS per la lettura dei selettori e della loro specificità. Release checks: Check content order, shared design values, component consistency, contrast, zoom, and layout changes by screen size. Verify every theme, language, and state. If there is motion, offer an equal reduced-motion experience. Before changing code, list the evidence, gaps, severity, and the smallest safe fix.