HTML and CSS Reference
In-Depth Information
Some things to note about !important declarations:
When !important was first introduced in CSS1, an author rule with an !
important declaration held more weight than a user rule with an !
important declaration; to improve accessibility, this was reversed in CSS2
• If !important is used on a shorthand property, this adds “importance”
to all the sub-properties that the shorthand property represents
• The !important keyword (or statement) must be placed at the end of
the line, immediately before the semicolon, otherwise it will have no
e " ect (although a space before the semicolon won't break it)
• If for some particular reason you have to write the same property twice
in the same declaration block, then add !important to the end of the
first one, the first one will have more weight in every browser except IE6
(this works as an IE6-only hack, but doesn't invalidate your CSS)
• In IE6 and IE7, if you use a di " erent word in place of !important
(like !hotdog ), the CSS rule will still be given extra weight, while other
browsers will ignore it
When Should !important Be Used?
As with any technique, there are pros and cons depending on the
circumstances. So when should it be used, if ever? Here's my subjective
overview of potential valid uses.
NEVER
!important declarations should not be used unless they are absolutely
necessary after all other avenues have been exhausted. If you use !
important out of laziness, to avoid proper debugging, or to rush a project
Search WWH ::




Custom Search