To follow up on the complicated subject of CSS hierarchy here is a detailed guide to which CSS rule is applied when there is a CSS conflict:
The short version of this guide is:
- Inline CSS (inside your HTML and not in and external file) take priority over ID's, classes, elements.
- ID's take priority over classes and elements.
- Classes take priority over elements.
- Elements are at the bottom of the hierachy.
But, it can get much trickier than this. The best strategy for avoiding errors due to CSS hierachy complications is to organize your formatting without CSS conflicts in the first place. Sometimes this is not possible, and at that point you need to dig in and learn the hierarchy.
No comments:
Post a Comment