It seems the following variants produce identical results:
/* 1 */ a, a:visited, a:active { color: black; } a:hover { color: red; } /* 2 */ a, a:link, a:visited, a:active { color: black; } a:hover { color: red; } /* 3 */ a:link, a:visited, a:active { color: black; } a:hover { color: red; }
Most guidance on the web uses 2 or 3. Why not go for the simplest variant which is 1? I cannot find a good reason to ever apply :link
if all you need is one style for normal links and one for hover.
Is it best-practice to not use :link
? Why or why not?
I don't care whether the link is visited or not. Both receive the same style. I only care about hover or not hover. This question is not about what the variants do - all do the same thing. It is about what the best variant is. Is one of the variants faulty? Which one is best-practice?
Because not every a
is a link.
<a name="table_of_contents">Table of Contents</a>
isn't a link, it's an anchor that can be linked to with <a href="#table_of_contents">
.
a
will match it, a:link
won't.
It is used to differentiate between simple anchors and anchors with href attributes. See demo jsfiddle here.
<style> a { color: red; } a:link { color: blue; } </style> <a name="anchor">No href</a><br /> <a href="http://stackoverflow.com/">With href</a>
EDIT: For this reason, it is important to cover all cases in your CSS. Option 2 is the only option that completely covers all cases. If you do not have anchor elements without href
attributes, you are safe with option 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With