Search code examples
csshyperlinkvisited

Is it possible to set a style of link that shows only when the linked webpage is being viewed?


I got a problem like this (this is html/css menu):

Eshop | Another eshop | Another eshop

Client wants it work like this:

User comes to website, clicks on Eshop. Eshop changes to red color with red box outline. User decides to visit Another eshop, so Eshop will go back to normaln color without red box outline, and another eshop will do the red outline trick again..

I know there is A:visited but I don't want all visited menu links to be red with red box outline.

Thx for any help :)


Solution

  • The same that Joe Skora has written but more specific:

    .red {
        outline-color:red;
        outline-width:10px;
    }
    

    Now you could use Javascript (in this example using jQuery) in the click-event-handler:

    $('.red').removeClass('red'); // removes class red from all items with class red
    $(this).addClass('red'); // adds class red to the clicked item
    

    Another way of doing it is the use of the pseudo selector :target.
    For informations about it: www.thinkvitamin.com