Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"! important" in CSS (?) 1

Status
Not open for further replies.

popcity

Technical User
Mar 30, 2002
6
GB
I noticed this in the CSS of a site (on many of the elements):

TD {
color: #000000 ! important;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}


with "! important" in bold red.
Could someone tell me what the "! important" is for and does it work?

- popcity
 
Hi mate,

CSS tries to create a balance of power between author and user style sheets. By default, rules in an author's style sheet override those in a user's style sheet.

However, for balance, an "!important" declaration takes precedence over a normal declaration. Both author and user style sheets can contain "!important" rules, but user "!important" rules override author "!important" rules.

In CSS1, it works the other way: Author "!important" rules took precedence over user "!important" rules.

If you, in your style sheet want to mark something as important, use the following code:

P { font-size: 18pt ! important }


You are telling your user, that it is important, that you use 18pt, as your fontsize.

Hope this helps

Wullie

 
When you set your CSS anyway, whatever you specify first is set first in the hierarchy of the attribute.
If you want the size to be kicked in first its best to specify that higher in the hierarchy of the attribute.. In your example you have specified the color first and the size last...

I don't believe that it is deemed good practice to use the important tag.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top