Pseudo-Class Selectors

Pseudo-class selectors match elements according to a condition not involving their name. There are seven of these separated from the element name by a colon.

first-child

This pseudo-class matches the first child element of the named element. When applied to Example 13-1, this rule italicizes the first, and only the first, step element:

step:first-child {font-style: italic}
link

This pseudo-class matches the named element if and only if that element is the source of an as yet unvisited link. For example, this rule makes all links in the document blue and underlined:

*:link {color: blue; text-decoration: underline}
visited

This pseudo-class applies to all visited links of the specified type. For example, this rule marks all visited links as purple and underlined:

*:visited {color: purple; text-decoration: underline}
active

This pseudo-class applies to all elements that the user is currently activating (for example, by clicking the mouse on). Exactly what it means to activate an element depends on the context, and indeed not all applications can activate elements. For example, this rule marks all active elements as red:

*:active {color: red}
linking

These pseudo-classes are not yet well-supported for XML documents because most browsers don’t recognize XLinks. So far, only Mozilla and Netscape 6/7 recognize XLinks, and they are the only browsers that will apply these pseudo-classes to XML.

hover

This pseudo-class applies to elements on which the cursor is currently positioned ...

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.