Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to add the background-image: property to visited links?

 a.coolLinks:visited{
     background-image:url("http://www.ledr.com/colours/black.jpg");
}

Thanks

Edit: So it appears that this is a security vulnerability and this is why it cannot be done. There was no indication that the browsers were blocking this css style.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
462 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your code is correct according to most specifications. However, many browsers consider background images on visited links a potential violation of user's privacy, so they do not allow it.

Observe this example:

<p><a href="/unvisited">Unvisited link</a></p>

<p><a href="http://jsfiddle.net/">Visited Link</a></p>

<style>
a {
  background:red url("http://placekitten.com/100/101?image=2") center center no-repeat;
  display: block;
  height: 200px;
  width: 200px;
  overflow: hidden;
  text-align: center;
  background-color: red;
}

a:visited {
  background:blue url("http://placekitten.com/100/100?image=1") center center no-repeat;
}
</style>

(Also at http://jsfiddle.net/Yq5GY/1/). Firefox ignores the background image declaration for visited links, and never displays the solo kitten. You can do some differentiation with background color. It's bad usability to rely on images alone, anyhow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...