For myself I find those approaches which use additional, non CSS code too complicated and adding the .current class to a different navigation link per page works only as long as you are not using a server-side include for the whole navigation bar.
So, what’s the solution?
A simple 3 step process:
Add an ID to the body tag of every page which will be linked to from the navigation bar. For example
<body id="home"> or <body id="gallery">.
- Add an ID to each navigation link. (Remember: ID’s for single selectors, classes for multiple usages on a page). For example:
<a href="index.html" id="nav-home">Home</a>
<a href="products.html" id="nav-products">Products</a>
<a href="gallery.html" id="nav-gallery">Gallery</a>
<a href="about.html" id="nav-about">About</a>
- Add CSS selector which will highlight the current page.
Now you can add the HTML part into a server-side include (i.e. you need only to write it all 1x instead for each page separately) and without further ado your current page will be highlighted in the navigation bar.
Of course there are other ways how you can address the navigation links (e.g. body#home#navigation#nav-home etc.). Also, you’ll probably give the color not a web color name but either a hex or rgb color value.