homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

Distinguishing Link code
Assigning an style to a link but using a different style while on page.

Msg#: 4399968 posted 6:32 am on Dec 21, 2011 (gmt 0)

I set up a body-id to each page to make it simple to link to pages from the nav menu. The trouble is in changing the styles while visiting said page.

For example. I set up the default font color to white for all links on the nav bar, with a hover and active of blue with the following code:

#nav li a:link, #nav li a:visited {
color: white;

#nav li a:hover, #nav li a:active {
text-decoration: none;
color: blue;

Now say I want to change the link color to green after you click on one of the links and visit the page. So while on any given page, the link color for that page will be green.

How do I specify a different font color in this scenario?




WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

Msg#: 4399968 posted 9:10 am on Dec 21, 2011 (gmt 0)

You have already applied a unique id to the body of each page. You also need to apply a unique id to each of your links in your nav - since you need to target each link individually in order to style it.

Then you need to provide a style rule for each body/link combo... so that the link-to-page-N when actually on page-N is green.

#pageN #nav li a#linkpageN { 
color: green;

... repeat for each of your links.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved