On 16 Oct 2007, at 05:21, Alex Dunae wrote:

> Hello all - I'm writing a CSS parser and have come up against a bit of
> confusion regarding CSS specificity.
>
> In my style sheet I have
>
> #head a { color: white; }
>
>
> In my HTML document I have
>
> <div id="head"><a href="#" style="color: red;">...</a></div>
>
>
> Firefox and IE both render the link as red but the CSS spec seems  
> to say
> that it should be white.
>
> Per http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order
> the rule in my stylesheet should have a specificity of 101 while the
> inline attribute should have a lower specificity, 100.
>
> Am I reading this incorrectly or is this just browsers ignoring  
> part of
> the spec.

You are referring to the CSS 2 spec, rather than CSS 2.1. IN 2.1 it  
states:

"count 1 if the declaration is from is a 'style' attribute rather  
than a rule with a selector, 0 otherwise (= a) (In HTML, values of an  
element's "style" attribute are style sheet rules. These rules have  
no selectors, so a=1, b=0, c=0, and d=0.)"
<http://www.w3.org/TR/CSS21/cascade.html#specificity>

So the style attribute on the <a> has a specificity of 1000,  
overriding the 101 of the stylesheet rule.

HTH,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/
______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to