PDA

View Full Version : CSS nested !important tags



sekasi
June 7th, 2008, 03:27 AM
To make the post short, I just want some confirmation;

Nested !important tags on the same property always take priority the 'deeper' they are in the nest right?

ie;

#block {
color: #0A0A0A !important;
};
#block #block2 {
color: #FFFFFF !important;
}
#block #block2 #block3 {
color: #999999 !important;
}

So if there's text inside block3 that is nested, it'll get #999999 rite? Just trying to troubleshoot here, want to rule this factor out :kir:

simplistik
June 7th, 2008, 11:04 AM
wtf? why would you do it that way? if you get rid of important you'll get the same result, I fail to see what you're attempting to accomplish. of course block3 will be #999999 not because of the important flag, but because that's where it's at in the cascade.

Esherido
June 7th, 2008, 05:30 PM
Personally, I think !important tags are unnecessary and that a good designer shouldn't have to use them unless absolutely necessary. Especially considering the fact that a bunch of !important tags in a stylesheet would bring up its file size.

Jeff Wheeler
June 7th, 2008, 06:06 PM
That is correct.

It's good to understand the specificity rules and cascading properties of !important which are described on the CSS specification (http://www.w3.org/TR/REC-CSS2/cascade.html).