You've no doubt seen web pages that contain links that respond differently than the default behavior, which is to simply appear as underlined blue text (in most web browsers). Most browsers also change the color of a link to purple after the linked page or resource has been opened. This helps to indicate whether you've followed a link before. CSS includes a mechanism that allows you to change the appearance of links based on the state of the link. For the purposes of applying styles, you can think of a link as having four distinct states:
Each of these link states corresponds with a CSS pseudoclass, which is a special type of style class that applies to the state of an element. Pseudoclasses are unique in that you specify them using a colon (:) instead of a period (.). The pseudoclasses that apply to links are link, hover, active, and visited. To apply these pseudoclass styles, you attach them to the a element like this: a:link, a:hover, a:active, and a:visited. Following is an example of how to set styles for the a:link pseudoclass, which determines what a normal link looks like: a:link { color:#19619A; font-weight:bold; text-decoration:none; } Notice that underlining is removed from the link via the text-decoration:none setting, but the link is bolded via the font-weight:bold setting. The color #19619A is a light blue color. This style rule appears later in the lesson in a new version of the hockey player style sheet that you saw earlier in the book.
Following is how you would alter the previous link style so that it appears in a different color when the user hovers over it with the mouse: a:hover { background-color:gold; font-weight:bold; text-decoration:none; } Keep in mind that you can also change the appearance of a link when the link is active and after it has been visited. However, if you want a link to change its appearance only in response to a mouse hover, just set the a:active and a:visited style classes to match the a:link class.
|