Hi Christian,

I just wanted to add to Ryan's reply and explain why ID selectors take
precedence over Class selectors. It's because of something called
"specificity", which is basically the calculated "weight" of a
selector. The selector with the most weight gets applied last.

Selector specificity is calculated from the number of id attributes
(i.e. #content), class attributes (.custom), pseudo classes (:hover)
and element names (a) in a selector. Different attributes weight
differently, so you have 100 for an id attribute, 10 for class
attributes and pseudo classes, and 1 for element names. For example,
when you write a selector like "#content a.custom:hover", the weight
gets calculated as follows:

1 id attribute (#content) - 100
+ 1 element name (a) - 1
+ 1 class attribute (.custom) - 10
+ 1 pseudo class (:hover) - 10
------------------------------
specificity: 121

Hope that makes it clearer. You can read the part of the specification
that has more (and better) examples of calculating CSS specificity
here <http://www.w3.org/TR/REC-CSS2/cascade.html#specificity>.

-Tisho
______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
IE7b2 testing hub -- http://css-discuss.incutio.com/?page=IE7
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to