All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----org.w3c.css.css.CssCascadingOrder
Conflicting rules are intrinsic to the CSS mechanism. To find the value for an element/property combination, the following algorithm must be followed:
LI {...} /* a=0 b=0 c=1 -> specificity = 1 * / UL LI {...} /* a=0 b=0 c=2 -> specificity = 2 * / UL OL LI {...} /* a=0 b=0 c=3 -> specificity = 3 * / LI.red {...} /* a=0 b=1 c=1 -> specificity = 11 * / UL OL LI.red {...} /* a=0 b=1 c=3 -> specificity = 13 * / #x34y {...} /* a=1 b=0 c=0 -> specificity = 100 * /
Pseudo-elements and pseudo-classes are counted as normal elements and classes, respectively.
The search for the property value can be terminated whenever one rule has a higher weight than the other rules that apply to the same element/property combination.
This strategy gives author's style sheets considerably higher weight than those of the reader. It is therefore important that the reader has the ability to turn off the influence of a certain style sheet, e.g. through a pull-down menu.
A declaration in the 'STYLE' attribute of an element has the same weight as a declaration with an ID-based selector that is specified at the end of the style sheet:
<STYLE TYPE="text/css"> #x97z { color: blue } </STYLE> <P ID=x97z STYLE="color: red">
In the above example, the color of the 'P' element would be red. Although the specificity is the same for both declarations, the declaration in the 'STYLE' attribute will override the one in the 'STYLE' element because of cascading rule number 5.
The UA may choose to honor other stylistic HTML attributes, for example 'ALIGN'. If so, these attributes are translated to the corresponding CSS rules with specificity equal to 1. The rules are assumed to be at the start of the author style sheet and may be overridden by subsequent style sheet rules. In a transition phase, this policy will make it easier for stylistic attributes to coexist with style sheets.
public CssCascadingOrder()
public CssProperty order(CssProperty property, StyleSheet style, CssSelectors selector)
All Packages Class Hierarchy This Package Previous Next Index