CSS Specificity Explained: Why Your Style Is Not Applying
You wrote the rule, DevTools shows it, and it is crossed out. Specificity is almost always why. How it is scored Think of three columns: IDs, classes/attributes/pseudo-classes, elements. #nav .item a is (1,1,1). Higher column wins; ties go to the later rule. Things people get wrong !important and inline styles sit outside the normal scoring :where() has zero specificity; :is() takes its most…
The article explains the concept of CSS specificity and why your style may not be applying as expected. It introduces the scoring system, which involves three columns: IDs, classes/attributes/pseudo-classes, and elements. The higher the score in a column, the greater the specificity, and if there's a tie, the later rule takes precedence.
The article also highlights common mistakes, such as using !important or inline styles, which do not affect specificity, and using universal selectors, which add no specificity. It concludes by offering practical rules for styling, such as using single-class selectors and avoiding IDs, and suggests using a CSS specificity calculator to check the score of a selector.
Brief written by urgent.news; may contain errors — check the original.
Source: dev.to