You are going about this backwards. CSS rules have weight, and you should leverage those rules to correctly cascade styles.
element = 1 pt
class = 10 pt
id = 100 pt
inline = 1000 pt
!important = 10,000 pt
Consider this article on specificity
The !important
clause, while it certainly works, builds inflexibility into your cascading rules and it becomes far too easy to do end up with competing directives.
My basic principle is to "generally" avoid ID
s in CSS, and use them only when you need to override an existing class/element rule.
Ultimately, you are the author. Write your less specific rule as a class
, and override it with an ID
.
From my 14+ years building web stuff : if you have to use a !important
clause, you are doing it wrong. I consider it very smelly.
That said sometimes it happens. You inherit someone else's terrible css, it can be hard to avoid.
!important
is not 10,000 (although one could think of it that way). In fact,!important
has no specificity at all. Specificity applies only to selectors and!important
is not a selector (it's a rule). – Hangnail