Improperly Styling HTML Links

by @jehiah on 2006-08-25 02:44UTC
Filed under: All , HTML , Articles , CSS , IE , Firefox , Web

The part that always trips me up, is you can’t just style all anchor tags the same, you really only want

[css]
a:link, a:visited {color:#00f;}
[/css]

NOT

[css]
a{color:#00f;}
[/css]

because you could have

[html]
<a name="anchorID">heading</a>
[/html]

… which you would NOT want styled with all the other anchor elements because it is not a hyperlink.

When styled improperly you will see a link style in Firefox (and probably IE 7). IE6 of course makes up its own rules to how the style should be applied.

Why would you use the name attribute of anchor tag’s anyway? It allows you to jump to a specific section of the page by appending the anchorID after a hash mark (#) in the url. For example http://jehiah.com/archive/styling-links#Comments will jump you to the comments section

An alternative instead of the name attribute is to use an id attribute instead. They have nearly the same effect, just remember that ID’s have to be unique on an individual page.

Subscribe via RSS ı Email
© 2023 - Jehiah Czebotar