Delphinidin

Get any informations you need in depth explanation

Along with the need for the cascade in CSS is the need to override it. This is where !important rules come in. The !important syntax appears within a declaration, after the property value and before the semicolon that terminates the declaration. Two components make up this syntax: an exclamation mark, used here as a delimiter; and the important keyword. A delimiter marks the ending of one thing and the beginning of another. Here the exclamation mark signals the end of the declaration. The important keyword must appear next, followed by a semicolon to terminate the declaration; this is demonstrated in the following code.

body {background: #000 !important;}

A declaration containing the !important rule, like the preceding one, takes precedence over any other declaration even the style attribute. If more than one !important rule appears in a style sheet, and the style sheet has the same origin — that is, both rules come from the author’s style sheet or both come from the user’s style sheet — the latter rule wins out over any specified previously.

For this reason, it is strongly advised that you never use !important rules anywhere in your code. The only place that there could be a good reason for using one is in user defined style sheets when a specific style is required to make a site usable, for example specific foreground and background colors. Using !important rules in author style sheets makes it harder for users to define their own rules and makes site maintenance much more difficult as the only way to override an !important rule is to include another !important rule later in the author style sheet.

0 comments:

Post a Comment

Site Info