XML technologies / CSS / CSS Cookbook / Links and navigation / Adjusting link colours
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to change the colour used to display links.
Solution
Use the pseudo-classes to style links in this order: :link, :visited, :hover and :active:
body {
color: #99ffff;
}
a:link {
color: #33ccff;
}
a:visited {
color: #cecece;
}
a:hover {
color: #336666;
}
a:active {
color: #339999;
}Discussion
Hyperlink pseudo-classes have the same specificity. To prevent their values from overriding one another, use the selectors in this order: :link, :visited, :hover and :active. (Note: For a detailed discussion, see Chapter 3 of Eric A. Meyer’s CSS – Das umfassende Handbuch (O’Reilly).) The popular English mnemonic “LoVe/HAte” may help.
Both visited and unvisited links can be in the state :hover or :active. Because specificity is equal, their order in the CSS code determines which rule takes precedence. If the rule for :hover appears before that for :active or :visited, users may never see the definitions for :hover because the later definitions “mask” them.
See also
The CSS 2.1 specification on dynamic pseudo-classes :link, :visited, :hover, :active and :focus.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln