Links and Pseudo-Classes


You have already learned how to style <a> or link elements in Lesson 3, "Selectors in Action." Now you will learn how to style the five different link states.

Links can be in the following states:

  • Normal The standard unvisited link state

  • Visited The link points to a URI that has already been visited

  • Hover The cursor is over the active area of the link

  • Active The moment the link is selected or clicked

  • Focus The link is in focus and ready to accept input, such as a click or mouse down

Some link states cannot occur at the same time. For example, a link can either be visited or unvisitedit cannot be both. However, visited and unvisited links can also be in the hover, active, and focus states.

Each of these states can be styled individually using link pseudo-classes (classes that do not exist in the document structure). The five link pseudo-classes are

  • a:link Styles unvisited link elements

  • a:visited Styles visited link elements

  • a:focus Styles the state during focus

  • a:hover Styles the state when the cursor moves over a link

  • a:active Styles the state when a link is activated

The five pseudo-classes are shown in Listing 10.1.

Listing 10.1. CSS Code Containing the Five Link Pseudo-Classes
a:link {...} a:visited {...} a:focus {...} a:hover {...} a:active {...} 

Focus and Active States

The a:focus pseudo-class highlights the tab position for people who use a keyboard to navigate.


Unfortunately, Internet Explorer for Windows does not support the a:focus pseudo-class. Instead, it uses the a:active pseudo-class for tab highlighting.

As an additional problem, Internet Explorer for Windows incorrectly applies the a:active pseudo-class. The a:active state remains visible until another action takes place.





Sams Teach Yourself CSS in 10 Minutes
Sams Teach Yourself CSS in 10 Minutes
ISBN: 0672327457
EAN: 2147483647
Year: 2005
Pages: 234
Authors: Russ Weakley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net