20080905

The importance of !important in CSS

The importance of !important in CSS

#main {
max-width: 900px;
width:expression(document.body.clientWidth > 900? “900px”: “auto” ); /* IE proprietary code */
}

In this example the #main element will be rendered with a maximum width of 900px both in Firefox, Safari, Opera and Internet Explorer.
Please note that the proprietary code width:expression is not a valid CSS declaration, so if you decide to adopt it, your stylesheet won’t respect web standards and won’t be validated.
However, we can use the !important declaration to avoid non-standard CSS expressions. Here is a “workaround” which allows to use max/min width with smart browsers and specify a fixed width for IE 6 users:
#main {
margin: 0 auto 0;
max-width: 900px;
min-width: 770px;
width:auto !important;
width:800px;
}

No comments:

Post a Comment