Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have made some links in my html page.
I want to show the selected link different from others.

For this purpose I have defined the css style as under for the links

CSS
a:link {background-color:#FF0000;}
a:visited {background-color:#00FF00;}
a:hover {background-color:#FF00FF;}
a:active {background-color:#0000FF}


When I apply this style to my links the a:visited color dominates the background color and when I select a link it does not changes its background color according to the style.

Can someone help me with this problem with my style.
Posted
Updated 27-Mar-11 5:29am
v3

1 solution

Your code works correctly, even though this is a bad style. I do understand your ugly colors are just for example. You should not ever change background color for such cases.

The reason you may not see the difference is your visited links: which links are visited are defined by what's in the cash of your Browser. I try to test your code and did not see the difference between visited and not-visited links because it so happened that both ones from my test were actually visited.

As soon as I've chosen the link which I never visited (alternatively, you could wipe your browser's cash), you code started to work correctly.

[EDIT]
In response to discussion of the style: look at my two Answers to this Question: GUI Apperance - C#.Net[^].
Sorry this is not even about Web development, but it may give you some idea on how I approach it.
What do you think? I would be glad to here your opinion.

—SA
 
Share this answer
 
v2
Comments
rashidfarooq 28-Mar-11 8:07am    
You said that this is a bad style, I will be thankful if you guide me to a good style.
The point you have mentioned about visited and non-visited links is already in my knowledge. Therefore, Each time I tested this code, after cleaning the cache of the browser. But the Problem is When I select a link it does not change its color according to the defined style. What can be solution for that?
Sergey Alexandrovich Kryukov 28-Mar-11 10:32am    
As I say, I did not reproduce your problem. Your code is correct. Will you try a different Browser to see if there is a difference?

Style... I only mean graphical design, not your coding style. You see, everyone expects clarity; and some elements which are customary. In particular, links should be differentiated by underline and background color. Any background colors for non-block elements are problematic in principle.

As to the general styles: it's a long story; one can learn good taste for a lifetime; and I don't say I'm the real expert or something. I have some minimal experience with industrial design, but it is also based on my school of graphics and some painting... There are a number of guides, but some of them are really good, some are so-so. If you want to discuss some articles on that, I'll gladly read and share my opinion, but I'm not ready to write my own (maybe a list of short directions, as I did for windows programming). And, sorry, I don't know what to recommend right now (in English).

--SA
Sergey Alexandrovich Kryukov 28-Mar-11 21:41pm    
I also added a new reference, not to answer your question in full -- this would be impossible -- but just to give you some idea on what I'm talking about.
--SA
rashidfarooq 28-Mar-11 13:57pm    
Thanks SAKryukov for answering me. I agree with you. After a lot of search I got that What I was trying to do is not possible through this css code. For that Purpose I wrote a new style class for the current selected link and with PHP I track the current selected link and applied this class to that link. And Now My Problem has been resolved.
By the Way, thanks for responding me so briefly.
Sergey Alexandrovich Kryukov 28-Mar-11 19:11pm    
If your agree with me, will you formally accept this Answer?
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900