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

Current page menu state

  • Can anyone share with me the best way (with CSS) to have the menu button of the page you are on stay in a state that shows that is where you are. kinda like it does right on this site.

    Thanks
  • I make a select id and add that to the link I want to highlight

    <a href=\"#\" id=\"select\" class=\"links\">Link</a>


    and whatever way I want my link to look like in the selected state i code for that in CSS

    #select {...]


    although the body id seems a better idea I have never used it myself
  • It really depends on what sort of website you have. If it's just a few static HTML pages then the body id is the way to go.

    If you are serving up your pages dynamically with PHP then you can use something like:

    <?php $activePage = basename($_SERVER['SCRIPT_NAME']); ?>


    And if you are using something like Wordpress then the class current_page_item is already added for you.