CSS

css/nesting-no-concat

In native CSS nesting, never build class names from "&" plus a suffix (&__title); write the full selector.

poważnastatycznefe-css-modern

Dlaczego

Sass taught a habit: &__title inside .card becomes .card__title. Native CSS nesting does not join text; & stands for the parent selector as a whole, so &__title is not a valid selector and the browser drops the whole rule. The styles silently disappear when a stylesheet moves from .scss to .css.

Poprawka

Write the full class name as its own rule or nested with a space (& .card__title for a descendant), and use &.modifier for a compound selector. Keep suffix joining in .scss files only, or in a build that runs postcss-nested.

Przykłady

/* bad */
.card { &__title { font-size: 1.25rem; } }
/* good */
.card__title { font-size: 1.25rem; }
.card { &.card--featured { border-color: gold; } }

Źródła

Fakty

Identyfikator
css/nesting-no-concat
Waga
poważna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
css
Uczy jej skill
fe-css-modern Modern CSS features
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain css/nesting-no-concat