Brought to you by Style Master

 

cascading style sheets guide

Pseudo Class Selectors

Explained

The selectors we have seen so far are general purpose. The two which follow are quite specific. The pseudo class selector lets you select links in a number of different states. Links can be normal (the usual state of an unvisited link), visited, active (while they are being clicked) or (only with Internet Explorer) in the hover state (with the cursor over them). With pseudo class selectors, you can give a link a different appearance in each of these different states.

Syntax

The selectors for each of the pseudo classes have the following forms

Use

With this type of selector, you can make links appear differently in different states. While this is possible with the traditional BODY tag in HTML, that only allows you to specify a color for links in these different states. With the pseudo class selector, any property which you can assign to an element can be assigned to a link in any state. You might change the background color, or the font, or both once a link has been visited for instance.

You can use these in conjunction with class selectors to create different types of link for different purposes. For example, you might create a class of onsite, and a class of offsite links. You can then use the class selector in conjunction with the pseudo-class selector to make the different types of link appear differently in various states.

For example,

A.offsite:link {color: red}

A.offsite:hover {color: green}