HTML and CSS Reference
As you might expect, you can string these two together as :nth-of-type(1):nth-last-
of-type(1) to restate :only-of-type , only with higher specificity. (We will explain
specificity later in this topic, I promise.)
Beyond the structural pseudo-classes, there are a set of pseudo-classes that relate to
structure but can change based on changes made to the page after it's been rendered.
In other words, the styles are applied to pieces of a document based on something in
addition to the structure of the document, and in a way that cannot be precisely deduced
simply by studying the document's markup.
It may sound like we're applying styles at random, but not so. Instead, we're applying
styles based on somewhat ephemeral conditions that can't be predicted in advance.
Nevertheless, the circumstances under which the styles will appear are, in fact, well-
defined. Think of it this way: during a sporting event, whenever the home team scores,
the crowd will cheer. You don't know exactly when during a game the team will score,
but when it does, the crowd will cheer, just as predicted. The fact that you can't predict
the moment of the cause doesn't make the effect any less expected.
Consider the anchor element ( a ), which (in HTML and related languages) establishes
a link from one document to another. Anchors are always anchors, of course, but some
anchors refer to pages that have already been visited, while others refer to pages that
have yet to be visited. You can't tell the difference by simply looking at the HTML
markup, because in the markup, all anchors look the same. The only way to tell which
links have been visited is by comparing the links in a document to the user's browser
history. So there are actually two basic types of anchors: visited and unvisited.
CSS2.1 defines two pseudo-classes that apply only to hyperlinks. In HTML, these are
any a elements with an href attribute; in XML languages, they're any elements that act
as links to another resource. Table 1-2 describes these two pseudo-classes.
Table 1-2. Link pseudo-classes
Refers to any anchor that is a hyperlink (i.e., has an href attribute) and points to an address that has
not been visited.
Refers to any anchor that is a hyperlink to an already visited address. The styles that can be applied to
visited links are severely limited; see sidebar “Visited links and privacy” on page 45 for details.