Page 1 of 1

Anchor pseudo-classes in CSS (glowing hyperlinks) Rate Topic: -----

#1 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Posted 05 April 2008 - 02:01 PM

Ok, before you begin, you should have some basic understanding of CSS.

Now, have you ever seen a website where the hyperlinks grow when you mouse over them, or underline themselves? The code behind these hyperlinks is relatively easy, yet if used correctly, can make you site look more professional.

First, you need to know about pseudo-classes. The syntax for these in CSS is:
selector.class:pseudo-class {attribute}
In otherwords, CSS defines a number of classes relative to the user or the surrounding code which it can use to apply to a class of a certian selector.

The most unique are the anchor (hyperlink) pseudo classes. These have special effects when they are clicked or moused over. The default color and the "clicked" color of hyperlinks is determined by the surrounding font color, but now you are not limited by this. Take the following code:
/* colors will be: */

/* normal link- yellow */
/* visited link- cyan */
/* mouse over link- firebrick */
/* selected link- lawn green */

a.one:link {color: yellow}
a.one:visited {color: #00FFFF}
a.one:hover {color: #B22222}
a.one:active {color: #7CFC00}


This code defines the different colors of all hyperlinks with the class attribute of "one" to have certian colors, while not affecting those which don't have both the pseudo-class and the normal class. For example <a href="#">unaffected</a> would be unaffected but <a href="#" class="one">affected</a> would be affected by the css class.

Now for the fun part...

The hover pseudo-class can be used to create special effects beyond coloration. Take (for example) the following Style Sheet:
a.grow:link {color: #ff0000}
a.grow:visited {color: #0000ff}
a.grow:hover {font-size: 150%}

a.highlight:link {color: #ff0000}
a.highlight:visited {color: #0000ff}
a.highlight:hover {background: #66ff66}

a.chngfont:link {color: #ff0000}
a.chngfont:visited {color: #0000ff}
a.chngfont:hover {font-family: monospace}

a.underline:link {color: #ff0000; text-decoration: none}
a.underline:visited {color: #0000ff; text-decoration: none}
a.underline:hover {text-decoration: underline}

All of these link classes each have their own action when they are moused over. You can also put most other identifiers next to the a:hover line. Thats pretty much it for anchor pseudoclasses. Hopefully, more tutorials to come!

Thats all folks! B)

This post has been edited by polymath: 11 April 2008 - 10:46 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1