Previous Section  < Day Day Up >  Next Section

Recipe 1.3 Enforcing Font Sizes

Problem

You want to override control over font sizes.

Solution

Use the !important rule to override a user's style sheet rules:

P {

 font-size: 12px !important;

}

Discussion

The !important rule consists of an exclamation mark (!) followed immediately by the word important.

In some browsers, a user can have a style sheet set up for browsing the Web that enables him to set font sizes (and other CSS properties) to his liking. However, as a designer of a web document, you might want to make sure your designs render in the manner you planned. The !important rule gives you a little insurance that your designs remain intact. (However, the nature of the medium means that designs are never precise or "pixel-perfect" from one display to another.)

Although you as the designer write the !important CSS rules, the user also can write these rules in his own style sheet. And in the CSS 2 specification, !important rules the user writes override any !important rules the designer writes.

See Also

The CSS 2.1 specification on !important rules at http://www.w3.org/TR/CSS21/cascade.html#important-rules.

    Previous Section  < Day Day Up >  Next Section