CSS Tutorial
CSS specificity determines which styles override others. It's calculated based on the following rules:
style="color: red"
) have the highest specificity.#header
) have the next highest specificity..header
) have lower specificity than ID selectors.header
) have the lowest specificity.Specificity is calculated using a 3-part system:
The following CSS rules have the following specificity:
#header { color: red; }
(Specificity: 100).header { background: blue; }
(Specificity: 10)header { font-size: 16px; }
(Specificity: 1)The CSS rule with the highest specificity will be applied. In the example above, the inline style on the <header>
element overrides the other two rules because it has a higher specificity.
By following these steps, you can ensure that your CSS styles are applied as intended and avoid unintended conflicts.