Grow your CSS skills. Land your dream job.

Current page menu state

  • # March 16, 2009 at 10:58 pm

    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

    # March 17, 2009 at 12:05 am

    I usually do it with the body ID:

    http://css-tricks.com/video-screencasts … e-body-id/

    # March 17, 2009 at 7:21 am

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

    Code:

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

    Code:
    #select {…]

    although the body id seems a better idea I have never used it myself

    # March 17, 2009 at 7:38 am

    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:

    Code:
    < ?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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".