Working with Link StatesFirst things first! Several states for links are considered standard for all browsers:
CSS categorizes the link and visited states as pseudo classes, and the hover and active states as dynamic pseudo classes. You can see how hover and active are dynamic: They require some kind of action from the user to work. The link and visited states occur before and after interaction. You might also remember from the discussion in Chapter 9, "Styling Text," the pseudo element selectors :first-child and :first-line. All pseudo selectors take the preceding colon. So, the corresponding selectors available to style links are :link, :visited, :hover, and :active. Example 10-1 sets up some general styles for the document, as well as styles for all link states. Example 10-1. Styling links using pseudo class and dynamic pseudo class selectorsTimes, serif; color: #ccc; background-color: black; You'll notice that I've styled the anchor element, too. Because the a However, there will be commonalities, so those common styles can be set in the anchor, with the independent styles in the selectors for each state. Figure 10-1 shows the document to which I've applied these styles. You'll notice my cursor hovering over a link so you can visualize the change. Figure 10-1. Viewing link and hover states in the context of a document.![]() NOTE For link effects to work properly, they must appear in this order: link, visited, hover, active. Any other order will cause inconsistent behavior. Just remember the order of LVHA, or, as a popular mnemonic in the industry goes, LoVe/HAte. I enlarged the link text to demonstrate more clearly the appearance of each state (see Figure 10-2). Figure 10-2. Link, visited, hover, and active states.
|
| |||||||||||||||||||