I have a little website with 5 nav sections.
For avoid change the code on every page when I have to add one more sections, I use a php include on the nav section of every page.
Now I need to add class “selected” to the list item (li) depending the page visited. ¿How to do this? Because now the nav is unique.
This is the code
<nav>
<ul>
<li class="selected"><a href="index.php">Home</a></li>
<li><a href="biography.php">Bio</a></li>
<li><a href="photo.php">Photo</a></li>
<li><a href="work.php">Work</a></li>
<li class="last"><a href="contact.php">Contact</a></li>
</ul>
<div class="clear"></div>
</nav>
Thanks!
Here’s the easy way to do it, pure CSS no need for any programming: Add an ID to your body and your links:
Now, you just style like this: