noImportantStyles
Это содержимое пока не доступно на вашем языке.
Summary
Section titled “Summary”- Rule available since:
v2.0.0 - Diagnostic Category:
lint/complexity/noImportantStyles - This rule is recommended, which means is enabled by default.
- This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "complexity": { "noImportantStyles": "error" } } }}Description
Section titled “Description”Disallow the use of the !important style.
The !important CSS style is a declaration used to give a specific rule
higher precedence over other conflicting rules. When it is applied to a CSS
property, that property’s value is prioritized over any other declarations,
regardless of specificity or order of appearance in the stylesheet.
How !important Works
Section titled “How !important Works”- Normally, CSS rules follow a cascade order, where the browser decides which rules apply based on specificity, inheritance, and proximity to the targeted element.
- Adding
!importantto a rule overrides this cascade logic, forcing the rule to apply even if other rules have higher specificity or are defined later.
Why !important Should Be Avoided
Section titled “Why !important Should Be Avoided”While !important can solve specific and immediate styling issues, its effects
can result in long-term problems within a codebase:
- Breaks the Cascade Logic: It overrides the natural flow of cascading rules, making it harder to predict which styles will apply.
- Increases Complexity: Once
!importantis used in a stylesheet, other developers may respond by using it even more aggressively, creating a cycle of overrides and increasing maintenance difficulty. - Reduces Reusability: Overriding styles often makes components less flexible, as future adjustments require more effort.
- Hinders Debugging: Debugging styles becomes more challenging, as developers
must account for the
!importantrule overriding expected behavior.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”.style { color: red !important;}code-block.css:2:16 lint/complexity/noImportantStyles FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid the use of the !important style.
1 │ .style {
> 2 │ color: red !important;
│ ^^^^^^^^^^
3 │ }
4 │
ℹ This style reverses the cascade logic, and precedence is reversed. This could lead to having styles with higher specificity being overridden by styles with lower specificity.
ℹ Unsafe fix: Remove the style.
2 │ ····color:·red·!important;
│ -----------
Useful links
Section titled “Useful links”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.