4

In my application I need to change the font size of the links that are visited. What I'm doing is

a:visited { 
    color: pink;
    font-size:12px;
}

But only the color is getting changed. Why is the font size not changing ?

I'm nidhin
  • 2,592
  • 6
  • 36
  • 62

4 Answers4

5

Limitations of :visited

The :visited pseudoselector has some limitations with regards to what properties it can target and sadly font-size isn't one of them :

enter image description here

Acceptable Properties

As seen above, the only acceptable styles that can be targeted are :

  • color
  • background-color
  • border-color
  • border-{bottom,left,right,top}-color
  • outline-color
  • column-rule-color

This is done for security/privacy reasons and isn't likely going to change any time soon. If you really had to implement this, you would likely need to resort to some Javascript to explicitly set the size on your visited tags.

Rion Williams
  • 74,820
  • 37
  • 200
  • 327
  • 2
    Better reference https://developer.mozilla.org/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector – j08691 Jul 14 '16 at 13:49
  • Thanks for pointing that one out. I frequently use Mozilla's documentation as I find it reads well, but that one is solid and focuses on the exact issue (not to mention it's present in the image I linked to). +1 – Rion Williams Jul 14 '16 at 13:51
0

Browsers limits the styles that can be set for a:visited links, due to security issues.

Allowed styles are:

  • color
  • background-color
  • border-color (and border-color for separate sides)
  • outline color
  • column-rule-color
  • the color parts of fill and stroke

All other styles are inherited from a:link.

Anuj Kumar
  • 136
  • 6
0

You can only change any color of visited (:visited) links but not the size. You can only change the size of a:link {font-size: 150%} of "NOT" visited links

Denis
  • 33
  • 6
-1

So all the other answers have established that this can not be done with pure CSS. So JavaScript to the rescue.

https://jsfiddle.net/dustinpoissant/708fwntf/

$(function(){
  $("a").each(function(index, link){
    var $link = $(link);
    console.log($link.css("color"));
    if($link.css("color") == "rgb(0, 0, 238)"){
      $link.addClass("visited");
    }
  })
});
a:visited { 
    color: pink;
}
a.visited {
  font-size: 26px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#">Test</a>
Dustin Poissant
  • 3,201
  • 1
  • 20
  • 32
  • 1
    try to use a real href attribute: the page will be unloaded and the classname won't be applied (if the target is `_self` by default) - maybe you could instead save the information in the localstorage for each clicked link and load from there at every page load – Fabrizio Calderan Jul 14 '16 at 14:01
  • I do not know what you mean by "page will be unloaded" you can leave and come back and it works fine. And if you use localstorage you are assuming that the link was visited from this site whereas it could be visited from another site, then you come to this site and this example should still work. – Dustin Poissant Jul 14 '16 at 14:08