"My CSS isn't applying" is almost always a specificity fight. The browser scores every selector โ the higher score wins.
The scoring
- Inline
style=""โ 1000 - ID
#navโ 100 - Class / attribute / pseudo-class
.card [type] :hoverโ 10 - Element / pseudo-element
p ::beforeโ 1
So #sidebar a (101) beats .sidebar .menu .link.active (40) โ even though the second looks more specific.
Debugging in 30 seconds
DevTools โ Elements โ Styles panel. Struck-through rules lost the specificity fight; the winner shows on top with its selector.
How to stay out of trouble
- Style with single classes; never IDs
- Keep selectors flat:
.card-title, not.page .card div h3 - Treat
!importantas a last resort โ it starts an arms race - Equal specificity โ later rule wins; use source order deliberately
More in the Complete CSS Guide.