Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background-image: for :visited links?

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.

like image 811
user1530249 Avatar asked Jan 07 '13 19:01

user1530249


People also ask

Can you make a background image a link?

You can't. Background images are not part of the HTML; they are part of the CSS. To make images clickable aka hyperlinked you need to insert them into your HTML.

How do you make a visited link color remains highlighted?

The way this is done in the "How to Make a Website" course is to use a "selected" class for the page you're on. This is taken straight from "about. html" from that course. The "selected" class is placed with the link for whatever that page is.

What is background image URL?

The url() value allows you to provide a file path to any image, and it will show up as the background for that element. You can also set a data URI for the url() .

What is the default appearance of a visited link?

By default, a link will appear like this (in all browsers): An unvisited link is underlined and blue. A visited link is underlined and purple. An active link is underlined and red.


1 Answers

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.

like image 113
KatieK Avatar answered Nov 10 '22 17:11

KatieK