Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS styling links: why a:link, a:visited vs just a

Tags:

css

i wonder why i can't use, or should not use

a { ... }

vs

a:link, a:visited { ... }
like image 287
Jiew Meng Avatar asked Jul 16 '10 11:07

Jiew Meng


2 Answers

If you only style a {...} then the style will be applied to all anchor elements including <a name="..."></a> elements, which define an anchor within the page, but do not reference a hyperlink.

a:link {...} specifically relates to hyperlinks. :visited, :hover and :active are different states of these links. Note that :hover and :active can apply to other elements as well.

like image 84
bluesmoon Avatar answered Nov 02 '22 23:11

bluesmoon


You may provide the general style for your links with the a only. More specific styles can than be applied to the pseudo-classes. For example:

a {
    text-decoration: none;
    font-weight: bold;
}

a:link {
    color: #00F;
}

a:hover {
    color: #F00;
}

a:visited {
    color: #888;
}

a:active {
    color: #0F0;
}

In this example, all links are styled bold and are not underlined. But the color changes for each type of link...

like image 33
Fidi Avatar answered Nov 03 '22 00:11

Fidi