Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlining visited links

Tags:

html

browser

css

Given the following example: http://jsfiddle.net/A8v9x/4/ - when you click the first link and then come back to the page, the first link turns green. However, it still does not have an underline, even though visited links are declared to have text-decoration:underline;. Nothing changes even if you add !important to that rule.

Could not find any information about such behavior in CSS spec. Is it a common browser bug? How does one work around it?

like image 440
naivists Avatar asked May 06 '12 15:05

naivists


People also ask

Do you underline a website link?

Assuming the link text is colored, it's not always absolutely necessary to underline it. There are two main cases in which you can safely eliminate underlines: navigation menus and other lists of links. However, this is true only when the page design clearly indicates the area's function.

What color of the link if is visited link with an underline?

Use blue for unvisited links and purple for visited links unless you have a reason to choose different colors. Test your color choice to make sure it stands out from the body text—and that it's visible to people who are color blind.

What are underlined links?

Links are easy to find because users understand that underlined text means that it's a link.

Should links be underlined for accessibility?

Best practice is to underline all links in content. However, if your links are not underlined, web accessibility guidelines (WCAG 2.0) require link text be discernable from body text by at least a 3:1 contrast ratio.


2 Answers

You can't change text-decoration in :visited. This is out of privacy concerns which are discussed at https://developer.mozilla.org/en/CSS/Privacy_and_the_:visited_selector. Basically changing computed properties can allow websites to determine which sites a user has visited.

The CSS properties that can be used to style visited links are color, background-color, border-*-color, outline-color and, column-rule-color and, when both the unvisited and visited styles are colors (not paint servers or none), the fill and stroke properties. For properties that are not permitted (and for the alpha components of the permitted properties, when rgba() or hsla() colors or transparent are used), the style for unvisited links is used instead.

like image 109
Bill Avatar answered Sep 23 '22 07:09

Bill


I had the same problem yesterday and I found a workaround. In the old days I used to put the links with underline and visited links without, to be more simple for visitor to not click the same link twice.

I had a surprise yesterday when trying to do the same thing and was not working. I lost 30 minutes until I found on the internet that since 2007 all browsers limited the properties you can put to "visited" because of security reasons. They are only like 6-7 properties you can set to "visited". And one of them is border-color. Then I thought to set the underline to none, and use "border-bottom-color" for underlining. You cannot set "border-bottom-color:transparent;" for visited, but you can set the border-color the same color as parent element background-color. That will make the underline invisible once link is visited.

<style type="text/css">
body{color:black;background-color:white;}
a:link{color:blue;text-decoration:none;border-bottom: 1px solid;border-bottom-color:blue;}
a:visited{color:red;border-bottom-color:white;}
</style>

Or you can do the reverse (what you are asking) by setting the link border-color the same as background and a different color for the visited.

Demo to the reverse: https://jsfiddle.net/stfr9f9a

like image 25
crisc2000 Avatar answered Sep 23 '22 07:09

crisc2000