treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] nav background color after click

  • I created a hover effect for my nav links. I want the hover background color to stay after the user has clicked a particular nav link, so it will show them the site area they are in. This site does that, as do a number of others. How is it done?

    Thanks for any help!

    -Margaret

  • A couple ways to do this...

    A. Add a class to the current page item, e.g. "active"...You just simply move it to the respective page item on each separate html page

    B. Use Jquery to add/remove the "active" class as needed when the items are clicked.

  • Also, if you're using Wordpress you can just target the body class/ID to set the active class.

    Example: body.page-id-1 .active {color: red;}

  • Thank you both :-)