Twitter Bootstrap. Active menu item marking

14,404

Solution 1

You just have to add "active" in your li like :

<li class="active">
    <a href="#"></a> 
</li>

Solution 2

Add a class of the active to the li

http://twitter.github.com/bootstrap/components.html#navbar

Share:
14,404
Wolter
Author by

Wolter

Updated on June 04, 2022

Comments

  • Wolter
    Wolter almost 2 years

    I use standart twitter bootstrap menu:

    <ul class="nav nav-pills">
    <li><a href="#">...</a></li>
    <li><a href="#">...</a></li>
    </ul>
    

    How to mark active menu item?

  • Wolter
    Wolter about 11 years
    It's mark only one marked <li>, not current. It's static, not active.
  • Wolter
    Wolter about 11 years
    It's mark only one marked <li>, not current. It's static, not active.
  • Chris
    Chris about 11 years
    Just add some javascript to make it active
  • ashley
    ashley about 11 years
    then add a class to it anyway: .marked { background: red; } then put <li class="marked"></li> or in css declare: .nav li:first-child { background: red; }
  • Wolter
    Wolter about 11 years
    You mean something from standart Bootstrap js tools?
  • Chris
    Chris about 11 years
    Not necessarily, you can just add an id or whatever to identify each li and change their class to "active" when this page is loaded
  • Chris
    Chris about 11 years
    document.getElementById("idOfCurrentli").setAttribute("class‌​", "active");
  • Wolter
    Wolter about 11 years
    And how to define idOfCurrentli :) ?
  • Chris
    Chris about 11 years
    In your html : <li id="homePage"><a href="#">...</a></li> And then in the js of this page : document.getElementById("homePage").setAttribute("class", "active");