tags:

views:

53

answers:

3

Hello,

Why the following styling of the link does not work ?

<html>
<head>
<style type="text/css">
    a:link {color:#123456;}    /* unvisited link */
</style>
</head>

<body>
    <a href="http://www.google.com"&gt;Visit Google</a>
</body>
</html>

Thanks !

+2  A: 

It's because the link has been visited.

Try

a {color: blue;} /* unvisited link */
a:visited {color: orange;} /* visited link*/

If you remove the last declaration links will be blue regardless of :visited.

Josh K
and a:hover {color:#f00;} makes it red when you hold your mouse over it.
BerggreenDK
A: 

And you shouldn't rely on it working in the future:

http://blog.mozilla.com/security/2010/03/31/plugging-the-css-history-leak/

Azeem.Butt
This is about what script querying the DOM for style information sees. The :visited pseudo-class will still function for what the user sees (albeit with some limitations on what can be styled). DOM queries against style of anchors will always function as if the link was unvisited.
bcherry
+2  A: 

For some general best practices, the link styling hierarchy works like this:

a:link {
color: #ff0000;
}
a:visited {
color: #ff0000;
}
a:hover {
color: #cccccc;
}
a:focus {
color: #cccccc;
}
a:active {
color: #cccccc;
}

It's best to always apply all of these, whether you do them singly as above or like this:

a:link, a:visited {
color: #ff0000;
}
a:hover, a:focus, a:active {
color: #cccccc;
}

But regardless, the order is very important and things can be overwritten if it isn't followed.

Jonathan Stegall