Wednesday, April 19, 2006

Anchor tags with different styles

I was trying to get different anchor styles from an external css to work on my site. It was not doing what it was supposed to do for some reason. When I searched for the problem, i found that the tags must be declared in a specific way (Link, Visited, Hover, Active). If they are not declared in this way, the anchors will not work properly.

Now say we have a page A where we want to the anchor tags to have style S1. We can do the following:

<html>
<body class="wrapped">
</body>
</html>

.wrapped a:link {properties}
.wrapped a:visited {properties}
.wrapped a:hover {properties}
.wrapped a:active {properties}

where wrapped in the className, or we can define each anchor tags as such

<a href="#" class="bar">My Link</a>

a.bar:link {properties}
a.bar:visited {properties}
a.bar:hover {properties}
a.bar:active {properties}