简体   繁体   中英

Bootstrap 3 :How to display sub-menu of side navigation bar, bottom of each menu?

I am trying to make side navigation bar using Bootstrap 3. Now sub-menus are display right side of the each menu. I want to display it bottom of parent menu.

<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display: block; position: static; margin-bottom: 5px; *width: 180px;">


      <li class="dropdown-submenu">
        <a tabindex="-1" href="#">More options</a>
        <ul class="dropdown-menu">
          <li class="dropdown-submenu">
            <a href="#">More..</a>
            <ul class="dropdown-menu">
                <li><a href="#">3rd level</a></li>
                <li><a href="#">3rd level</a></li>
            </ul>
          </li>
        </ul>
      </li>


      <li class="divider"></li>
      <li class="dropdown-submenu">
        <a tabindex="-1" href="#">More options2</a>
        <ul class="dropdown-menu">
          <li><a tabindex="-1" href="#">Second level</a></li>
          <li class="dropdown-submenu">
            <a href="#">More..</a>
            <ul class="dropdown-menu">
                <li><a href="#">3rd level</a></li>
                <li><a href="#">3rd level</a></li>
            </ul>
          </li>
          <li><a href="#">Second level</a></li>
          <li><a href="#">Second level</a></li>
        </ul>
      </li>
    </ul>

Here is the Demo.

Edit: I try to do it using collapse jsfiddle.net/mridulpv/Wrh8x/5 . But still some problems. I want to hide collapse item at starting, and remove horizondal line etc.

You can achieve this effect by not removing the sub-menus from the document flow. This means everything gets pushed down when the menu item is hovered. This does cause a problem with the third level, as when you mouse-out of the third level everything collapses up and you lose focus, but I don't believe it would be hard to get this menu functioning with clicks instead of hovers. (simply add/remove a class on click. See Edit.)

But here's what you want to do:

.dropdown-submenu > .dropdown-menu{
    position: relative;
    left: 0;
    top: 0;
    margin: 0;
}

http://jsfiddle.net/HCxB8/4/

You'll see as you mouse over the menu gets pushed down. This is due to me positioning relative rather than absolute.

EDIT :

With a bit more fiddling I managed to get clicking to work with very minimal jquery and a bit more css:

JS:

$('.dropdown-submenu > a').click(function(){
    $(this).parent().children('.dropdown-menu').toggleClass('shown');
});

CSS:

.dropdown-submenu > .dropdown-menu{
    position: relative;
    left: 0;
    top: 0;
    margin: 0;
}

.dropdown-submenu:hover > .dropdown-menu{
    display: none;
}

.shown{
    display: block;
}

.dropdown-submenu:hover > .shown{
    display: block;
}

http://jsfiddle.net/HCxB8/5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM