When a button ignores a new color rule, adding another parent selector may make the immediate screenshot look right. It also leaves the underlying ownership unclear. First identify which declaration wins and why; then change the smallest rule that expresses the intended design.
Specificity is one stage of the cascade
A selector’s ID, class and type components matter only after earlier cascade decisions have established comparable declarations. Origin, importance and cascade layers can decide the result before specificity is considered. For otherwise competing rules, scoping proximity and source order can also resolve ties. Inline styles have special precedence within author styles, but they do not defeat every important declaration or every other cascade mechanism. MDN’s specificity reference describes these distinctions.
Consider this deliberately small example:
<div id="checkout">
<button class="action action--primary">Continue</button>
</div>
#checkout .action { color: #333; }
.action--primary { color: #fff; background: #17324d; }
If both declarations are normal author styles in the same layer, the ID-bearing selector wins. Moving the second rule a few lines lower does not overcome that difference.
Before changing the selector, ask whether checkout should own the button’s text color at all. A broad container rule can accidentally become the style API for every nested component.
Make ownership visible with layers
An explicit layer order gives a project a place for defaults, components and intentional overrides:
@layer defaults, components, overrides;
@layer defaults {
:where(button) { font: inherit; }
}
@layer components {
.action { color: #fff; background: #17324d; }
}
@layer overrides {
.checkout-action { background: #243f59; }
}
The later layer has higher priority for normal declarations, regardless of a competing earlier layer’s selector weight. Normal unlayered author rules outrank normal layered rules. Important declarations reverse layer order, and important layered declarations outrank important unlayered ones. These details make partially migrated stylesheets worth checking carefully. MDN’s layer reference documents the ordering.
The :where() wrapper contributes zero specificity. It is useful for defaults that consumers should override easily. Other selector components outside the wrapper still count.
Diagnose the rendered element
Select the actual element in developer tools, then inspect the computed property. Follow the winning declaration back to its source and inspect crossed-out competitors. Check whether the rule matches at all before calculating selector weights: a media query, wrong class, missing stylesheet or invalid value can explain the symptom.
Record four things beside the fix:
- The element and state, including focus, hover or disabled.
- The property that was wrong.
- The rule that previously won.
- The intended owner after the change.
This turns “CSS was fighting me” into a reproducible defect.
For the checkout example, a component modifier is easier to reason about than a chain of page IDs. If a third-party stylesheet forces a narrow important override, document that boundary and keep the override local. Important changes cascade priority; it does not add points to specificity.
Review states, not just a screenshot
A readable default button can still lose contrast when disabled, focused or placed over an image. Test each state against its actual background. Check keyboard focus independently from hover, and inspect both existing responsive breakpoints.
Naming conventions such as BEM can clarify component boundaries, but they do not change the cascade. A convention only helps when selectors and ownership follow it consistently. The durable result is a small, understandable override surface that the next component can use without escalating selector weight.

Sardar Mukhshaf
Full-Stack & DevOps Engineer
I build scalable web applications, secure backend systems, and production-ready cloud infrastructure. My engineering focus spans interface design, API architecture, deployment pipelines, and observability. Follow for more deep dives into system architecture, performance engineering, and emerging technologies.
More from the practice
Keep the useful ideas close.
Follow new articles with your preferred RSS reader.
Open the RSS feed ↗


