[CSS 2.1] Proposed Rewording for Cascading Rules

Currently, implementations differ on how to treat the interaction of 
style attributes and !important style declarations in style 
sheets.  IE/Win and KHTML give precedence to the !important 
declarations, while Gecko, Opera, and IE/Mac favor the 
attribute.  The section of the spec dealing with this issue is 
ambiguous, so I would propose changing it to side with IE/Win and 
KHTML by reading as follows:


"To find the value for an element/property combination, user agents 
must apply rules in the following priority order:

1. Find all declarations that apply to the element and property in 
question, for the target media type. Declarations apply if the 
associated selector matches the element in question.

2. Sort by importance (normal or important) and origin (author, user, 
or user agent). Those rules will apply from low priority to highest:
    A. user agent style sheets
    B. user normal style sheets
    C. author normal style sheets or attributes
    D. author important style sheets or attributes
    E. user important style sheets

Note that the priority order assigned here is more important than the 
specificity score assigned in the following rule 3.  (See the example 
in section 6.4.3 below.)

3. Prioritize by specificity of selector: more specific selectors 
will override more general ones. Pseudo-elements and pseudo-classes 
are counted as normal elements and classes, respectively.

4. Finally, prioritize by order specified: if two rules have the same 
weight, origin and specificity, the latter specified wins. Rules in 
imported style sheets are considered to be before any rules in the 
style sheet itself."


Then alter the mentioned example in 6.4.3 to read this way:

"<HEAD>
<STYLE type="text/css">
   #x97z { color: red !important }
</STYLE>
</HEAD>
<BODY>
<P ID=x97z style="color: green">
</BODY>

In the above example, the color of the P element would be red. Note 
that the !important declaration takes priority over the style 
attribute because of cascading rule 2. In the absence of the 
!important declaration, however (or if both declarations were so 
marked), the color of the P element would be green.  In that 
instance, the priority will be the same under cascading rule 2; 
however, the declaration in the "style" attribute will override the 
one in the STYLE element because of cascading rule 3, since it has a 
higher specificity."


This would resolve the ambiguity squarely in favor of IE/Win and 
Safari; however, I think this resolution makes the most intuitive 
sense.  While I would hate to force browsers into a state of 
non-compliance at this late stage, this question has arisen several 
times on the CSS-D list, and I therefore felt that the ambiguity was 
significant enough to consider resolving, even at "Last Call".

Thank you,

-Adam Kuehn

Received on Friday, 18 November 2005 20:34:06 UTC