Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable color change of anchor tag when visited

Tags:

html

css

anchor

I have to disable the color change of an anchor tag when visited. I did this:

a:visited{ color: gray } 

(The link is gray in color before visited.) But this is a way where I explicitly state the color after the link is visited, which is again a color change.

How can I disable the color change of an anchor tag when visited without doing any explicit color changes?

like image 666
popcoder Avatar asked Sep 03 '11 07:09

popcoder


People also ask

How do I change the color of a link I visited?

If it's deselected (by default), you are good. Go to Step 2. Step 2: Now go to Content > Fonts & Colors > Colors. In the “Colors” windows, change the color of “Visited Links:” to your desired one, select Always in the drop-down menu, and click the “OK” button to save your changes.


2 Answers

If you just want the anchor color to stay the same as the anchor's parent element you can leverage inherit:

a, a:visited, a:hover, a:active {   color: inherit; } 

Notice there is no need to repeat the rule for each selector; just use a comma separated list of selectors (order matters for anchor pseudo elements). Also, you can apply the pseudo selectors to a class if you want to selectively disable the special anchor colors:

.special-link, .special-link:visited, .special-link:hover, .special-link:active {   color: inherit; } 

Your question only asks about the visited state, but I assumed you meant all of the states. You can remove the other selectors if you want to allow color changes on all but visited.

like image 100
Ryan Avatar answered Sep 27 '22 01:09

Ryan


You can't. You can only style the visited state.

For other people who find this, make sure that you have them in the right order:

a {color:#FF0000;}         /* Unvisited link  */ a:visited {color:#00FF00;} /* Visited link    */ a:hover {color:#FF00FF;}   /* Mouse over link */ a:active {color:#0000FF;}  /* Selected link   */ 
like image 45
Rich Bradshaw Avatar answered Sep 27 '22 01:09

Rich Bradshaw