145
Top Answer
CSS specificity determines which styles win when there are conflicts.
Specificity Hierarchy (highest to lowest):
- Inline styles -
style="..."(1,0,0,0) - IDs -
#header(0,1,0,0) - Classes, attributes, pseudo-classes -
.btn,[type="text"],:hover(0,0,1,0) - Elements, pseudo-elements -
div,::before(0,0,0,1)
Calculating Specificity
/* 0,0,0,1 */
p { }
/* 0,0,1,0 */
.text { }
/* 0,0,1,1 */
p.text { }
/* 0,1,0,0 */
#main { }
/* 0,1,1,1 */
#main p.text { }
Important Notes:
!importantoverrides everything (avoid using it)- Later rules win if specificity is equal
*selector has 0 specificity
CSSWizard