HTML and CSS Reference
In-Depth Information
Let's take a look at what exactly these kinds of declarations are all about,
and when, if ever, you should use them.
A Brief Primer on the Cascade
Before we get into !important declarations and exactly how they work,
let's give this discussion a bit of context. In the past, Smashing Magazine has
covered CSS specificity in-depth, so please take a look at that article if you
want a detailed discussion on the CSS cascade and how specificity ties in.
Below is a basic outline of how any given CSS-styled document will decide
how much weight to give to di " erent styles it encounters. This is a general
summary of the cascade as discussed in the spec:
• Find all declarations that apply to the element and property
• Apply the styling to the element based on importance and origin using
the following order, with the first item in the list having the least weight:
Declarations from the user agent
Declarations from the user
Declarations from the author
Declarations from the author with !importan t added
Declarations from the user with !important added
• Apply styling based on specificity, with the more specific selector
“winning” over more general ones
• Apply styling based on the order in which they appear in the stylesheet
(i.e., in the event of a tie, last one “wins”)
Search WWH ::




Custom Search