CSS
css/no-important
!important appears only in utility classes, user-preference overrides and third-party overrides, never to win a specificity fight.
drobnastatycznefe-css-architecture
Dlaczego
An !important declaration can only be beaten by another !important, so each one invites the next and the cascade stops being readable. It is usually a sign that the selectors or the order of the stylesheets are wrong.
Poprawka
Put the styles in cascade layers in the order they should win (@layer reset, base, components, utilities;), lower the specificity of the rule you are fighting (:where(), one class), or move the override into the component. Keep !important for single-purpose utilities (.sr-only, .hidden), user-preference blocks (prefers-reduced-motion, forced-colors) and overrides of third-party inline styles; mark the last with fs-ignore css/no-important and the reason.
Przykłady
/* bad */
.header .nav a.active { color: #fff !important; }
/* good */
@layer base, components, utilities;
@layer components { .nav__link[aria-current="page"] { color: var(--color-on-brand); } }Źródła
Fakty
- Identyfikator
css/no-important- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
cssscsslesshtmlvuesvelteastro- Uczy jej skill
fe-css-architectureCSS architecture and tokens- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain css/no-important