Killersites Community: Highlight Current Page Plus! - Killersites Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Highlight Current Page Plus!

#1 User is offline   Eric 

  • PipPipPipPip
  • View blog
  • Group: Advanced Member
  • Posts: 2,430
  • Joined: 19-December 08
  • LocationCarlsbad, CA

Posted 26 December 2008 - 05:44 PM

This original article can also be found here on my website. Below I've compiled the three easiest ways to highlight the current page that your on. All three are coded clean and very simple to implement into your own project. The method that you choose to use simply comes down to the project at hand and your preferred coding style. Each are pretty self explanatory, so I'll just let the code explain itself. That's usually the way I learn best anyway!


OPTION #1

Here is a working example.

This one is the easiest and most basic of the three options listed. If you have a small site (1 to 5 pages) and your running .html extensions, and/or you don't want or need to use PHP Includes, then this method is the one for you!

Quote

#nav {
width:150px;
list-style:none;
margin:150px auto;
}
#nav a {
color:black;
text-decoration:none;
}
#nav a:active, #nav a:focus, #nav a:hover {
color:red;
}
a#current {
color:red;
}
a#current:active, a#current:focus, a#current:hover {
color:blue;
}

Quote




OPTION #2

Here is a working example.

If you use, or want to use PHP Includes on your website, then the simple code shone above will not suffice. Therefore, you'll need to get a little more creative and use this method (Option #2) or the next method (Option #3) instead. This method shone here, is usually my code of choice for the job at hand!

Quote

#nav {
width:150px;
list-style:none;
margin:150px auto;
}
#nav a {
color:black;
text-decoration:none;
}
#nav a:active, #nav a:focus, #nav a:hover {
color:red;
}
#home a#homenav, #about a#aboutnav, #contact a#contactnav {
color:red;
}
#home a#homenav:hover, #about a#aboutnav:hover, #contact a#contactnav:hover {
color:blue; /* add :active and :focus styles here also */
}

Quote




OPTION #3

Here is a working example.

And the final way of going about highlighting the current page's navigation link is to use a bit of PHP. A little explanation: This bit here in bold (which tells the PHP code which page your currently on) can be placed just about anywhere on the page, that is, as long as it's sitting above the #nav using it. In this case, and partly for simplicity purposes, I just placed it inside the body tag as you can see. However, and unless proven otherwise, I think I like it there! And I'd like to thank Ben Falk and John Beatrice for helping me to get this last one working.

Quote

#nav {
width:150px;
list-style:none;
margin:150px auto;
}
#nav a {
color:black;
text-decoration:none;
}
#nav a:active, #nav a:focus, #nav a:hover {
color:red;
}
a#current {
color:red;
}
a#current:active, a#current:focus, a#current:hover {
color:blue;
}

Quote


This post has been edited by Eric: 26 December 2008 - 05:48 PM

0

#2 User is offline   LSW 

  • View blog
  • View gallery
  • Group: Moderators
  • Posts: 7,981
  • Joined: 20-December 08
  • LocationJuneau AK

Posted 13 January 2009 - 12:02 PM

:cool:
Thank You, Migwetth, Gunalche’esh, Ha’w'aa, Danke

Kyle


"90% of user's 'problems' can be resolved by punching them -the other 10% by switching off their PCs."




0

#3 User is offline   daddyalfie 

  • PipPipPipPip
  • Group: Member
  • Posts: 229
  • Joined: 14-January 09
  • LocationNorth Carolina

Posted 02 May 2009 - 08:06 PM

WOW!

Need to study on that some!

Many thanks!

Alfie

PS So glad LSW approves!

This post has been edited by daddyalfie: 02 May 2009 - 08:12 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users