views:

908

answers:

5

I need to set the a:visited CSS to whatever color the normal a is set to.

What I want to be able to tell the browser is, for the visited links, use the same color as the unvisited links, whatever color it is.

I need to do this without specifying a particular color.

Like, if some weird browser comes along that uses "green" as the color for normal unvisited links, this CSS should instruct the browser to use that same green for visited links. Exactly what color is used by the browser should be transparent to my code.. hence the phrase "whatever color".

P.S. I know how to set a:visited and a to a particular color. That is not what I am asking.

P.P.S. I am willing to use JavaScript if I have to. But I am really hellbent on making the browser do this.

Why would I want to do something like that you ask?

The blue color that IE8 uses for links is kind of cool. It is not #0000FF. It is a nice shade of blue. So I want to set it for both visited and unvisited links. But I shouldnt take a screenshot or use some add-on to pick the exact hex value each time. If IE later changes the color to some other awesome shade, this code should just work. I don't want to again find the hex and change it all over my code.

This is just one reason. Don't give me the hex for that blue. Finding that out is easy but that wouldn't be the answer!

A: 

I don't think there is a pure CSS way of achieving this. I think you would need to use JavaScript to get the color of the a and then set a:visited to that color and this probably wouldn't work in all browsers unless there was an a{color:#dea} specified.

easement
exactly. I tried getting the built-in color for a. I only got empty string. Because as you rightly pointed out, it should be set. I am okay with using JavaScript if I have to. But this particular way you are talking about is not working.
Senthil
You will only get the color from the element's style attribute if it actually has a style attribute set. This is similar to width and height properties, you can't get those unless they are set. However, dom objects also have scrollHeight and scrollWidth as well as clientHeight and clientWidth, but I doubt there is a clientColor... or scrollColor, that would make no sense...
Zoidberg
A: 

What you can do is set

a {
  color:#0000FF;
}

and the visited will remain like that also.

Remember that different browsers show different colors as default, so specifying it is always a good idea if the color matters.

Tor Valamo
Is that the shade of blue IE8 uses? Thanks. But my question is really something different. If there is a solution, I'll be able to set visited color the same as normal a color in IE8, that's all. The IE8 thing is just an application of the solution to my question.
Senthil
Well, the visited is automatically set to the normal color, as long as you specify the normal one. If you don't specify the normal one, there is a purple thing. Also remember that browsers differ between the default colors for links. And I just primt screened it into photoshop to find the color of the default in IE8, and it's actually pure blue #0000FF.
Tor Valamo
Really? I set a{color:#0000FF;} and the shade changed. I am absolutely sure it is not #0000FF by default in IE8. And you still haven't understood my question. I know that the visited will be set to normal color if the normal color is set. But i don't want to set the normal color. I want the visited to take up the color of the normal without me setting a particular color for normal and/or visited.
Senthil
I know what you want, and I'm telling you the only solution to get the end result.
Tor Valamo
The default also varies with each user, so it would never be consistent. In IE8, goto Tools, Internet Options/Preferences/Whatever(it's at the bottom), then click the 'Colors' button in the bottom row, and you can see the colors spelled out for you.
Tor Valamo
Some even use windows standards, which means that the website default link color depends on the windows THEME.
Tor Valamo
I am aware of all those. You repeatedly ignore what I want to do. I am trying to fool around with HTML/CSS/JS and the browser. It is experimental. I repeatedly tell that **I just want to see if doing something is possible** and you repeatedly keep telling **why don't you get that result in a different way?** The result doesn't matter. I am curious about the "method" itself. That one particular method - instructing the browser to do one simple task (which seems impossible now)
Senthil
Both answers have been trying to tell you that it's impossible. And I didn't say "why don't you get the results in a different way" I said "This is THE ONLY WAY to get this result".
Tor Valamo
A: 

I will post my comment to your post, because some comments to your post are hidden.

Hi, I did not touch CSS since about 2 years, so I'm probably wrong, but maybe try a:visited{color: inherit;}, but I'm not sure if this will take color from a or from body. P.S. IE8 default blue color link for me is #0066cc

Mike
A: 

I don't think there's a pure CSS solution. Usually you would pick a color, and set both a:link and a:visited that same color.

I tried {color: inherit} but that was useless.

This jQuery solution works great though.

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
            type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
                var normalColor = $('a:link').css('color');
                $('a:visited').css('color', normalColor);
            });
        </script>
    </head>
    <body>
        <a href="http://www.google.com"&gt;Google&lt;/a&gt;
        <a href="nowhereyouvebeen">No where you've been</a>
    </body>
</html>
Danny Roberts
I tried it. But it is not working. I still see the visited link in purple color. I just used the code you have posted and checked to make sure jQuery is included and the function is called properly. I even alerted `normalColor` and it had the correct value. But the last line doesn't seem to have any effect. Am I missing something?
Senthil
Probably the best solution - I was quite surprised to discover the link colours are not part of the CSS2 system colour palette: http://www.codehouse.com/webmaster_tools/system_color_palette/ - but they're being deprecated in CSS3 anyway
HorusKol
A: 

Danny Robers script works for me in Firefox and Chrome (not sure about IE).

FWIW, the special value HyperlinkText would have been the "standard" way to do what you want, but it was dropped from CSS3 sometime in spring 2003.

It looks like Firefox is the only browser that started implementing it, because the following works for Firefox:

a:visited { color: -moz-hyperlinktext; }