HTML and CSS Reference
In-Depth Information
In subsequent years, the pseudo-class :focus has come into widespread use. Its place
in ordering of link styles is a matter of some debate, because it all depends on what you
want it to override and what should override it. Many accessibility experts recommend
placing it between hovering and activation, like so:
:link {font-weight: bold;}
:visited {font-style: italic;}
:hover {color: red;}
:focus {color: lime;}
:active {background: yellow;}
If you prefer the hover style to overrule the focus style, then you simply shift the focus
styles earlier in the stack.
The ability to chain pseudo-classes together eliminates all these worries. The following
could be listed in any order without any negative effects:
:link {color: blue;}
:visited {color: purple;}
:link:hover {color: red;}
:visited:hover {color: gray;}
Because each rule applies to a unique set of link states, they do not conflict. Therefore,
changing their order will not change the styling of the document. The last two rules do
have the same specificity, but that doesn't matter. A hovered unvisited link will not be
matched by the rule regarding hovered visited links, and vice versa. If we were to add
active-state styles, then order would start to matter again. Consider:
:link {color: blue;}
:visited {color: purple;}
:link:hover {color: red;}
:visited:hover {color: gray;}
:link:active {color: orange;}
:visited:active {color: silver;}
If the active styles were moved before the hover styles, they would be ignored. Again,
this would happen due to specificity conflicts. The conflicts could be avoided by adding
more pseudo-classes to the chains, like this:
:link:hover:active {color: orange;}
:visited:hover:active {color: silver;}
Chained pseudo-classes, which lessen worries about specificity and ordering, would
likely be used much more often if Internet Explorer had historically supported them.
(See Chapter 1 for more information on this subject.)
Non-CSS Presentational Hints
It is possible that a document will contain presentational hints that are not CSS—e.g.,
the font element. In CSS 2.1, such presentational hints are treated as if they have a
specificity of 0 and appear at the beginning of the author's style sheet. Such presentation
hints will be overridden by any author or reader styles, but not by the user agent's styles.
Search WWH ::

Custom Search