22.04.2013 Views

HTML, XHTML & CSS

HTML, XHTML & CSS

HTML, XHTML & CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

74<br />

Part III: Taking Precise Control Over Web Pages and Styles<br />

The most common <strong>CSS</strong> use of pseudo classes is to define a style rule for a<br />

given element in the document tree — a technical term that just means the<br />

browser builds a hierarchical representation for all elements in a document,<br />

much like a family tree, where every element has a parent and may contain a<br />

child. For example, :link is a pseudo class that defines style rules for any<br />

link that hasn’t yet been visited.<br />

The five common pseudo classes that you can use with hyperlinks are<br />

✓ :link defines formatting for links that haven’t been visited.<br />

✓ :visited defines formatting for links that have been visited.<br />

✓ :focus defines formatting for links that are selected by the keyboard<br />

(for example, by using the Tab key) and are about to be activated by<br />

using the Enter key.<br />

✓ :hover defines formatting for links when the mouse cursor hovers over<br />

them.<br />

✓ :active defines formatting for links when they are selected (clicked by<br />

the mouse, or activated by pressing Enter).<br />

The pseudo class name is preceded by a colon (:).<br />

Pseudo classes can be used with<br />

✓ Elements (such as the element that defines hyperlinks)<br />

✓ Classes<br />

✓ IDs<br />

For example, to define the style rules for visited and unvisited links, use the<br />

following syntax:<br />

✓ The following sets the color of any hyperlink pointing to an unvisited<br />

URL to red by using its hexadecimal value:<br />

a:link {color: #FF0000;}<br />

✓ The following sets any hyperlink that points to a visited URL to appear<br />

in the named color green:<br />

a:visited {color: green;}<br />

✓ The following designates unvisited links with a class of internal to<br />

appear in (named color) yellow: (See Chapter 9 for a discussion of <strong>CSS</strong><br />

classes.)<br />

a.internal:link {color: yellow;}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!