Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Multilevel Dropdown Menu

Is it possible to have a multi level dropdown menu by using the elements of twitter bootstrap 2? The original version doesn't have this feature.

like image 256
Hellnar Avatar asked Mar 18 '12 13:03

Hellnar


1 Answers

Updated Answer

* Updated answer which support the v2.1.1** bootstrap version stylesheet.

**But be careful because this solution has been removed from v3

Just wanted to point out that this solution is not needed anymore as the latest bootstrap now supports multi-level dropdowns by default. You can still use it if you're on older versions but for those who updated to the latest (v2.1.1 at the time of writing) it is not needed anymore. Here is a fiddle with the updated default multi-level dropdown straight from the documentation:

http://jsfiddle.net/2Smgv/2858/


Original Answer

There have been some issues raised on submenu support over at github and they are usually closed by the bootstrap developers, such as this one, so i think it is left to the developers using the bootstrap to work something out. Here is a demo i put together showing you how you can hack together a working sub-menu.

Relevant code

CSS

.dropdown-menu .sub-menu {     left: 100%;     position: absolute;     top: 0;     visibility: hidden;     margin-top: -1px; }  .dropdown-menu li:hover .sub-menu {     visibility: visible;     display: block; }  .navbar .sub-menu:before {     border-bottom: 7px solid transparent;     border-left: none;     border-right: 7px solid rgba(0, 0, 0, 0.2);     border-top: 7px solid transparent;     left: -7px;     top: 10px; } .navbar .sub-menu:after {     border-top: 6px solid transparent;     border-left: none;     border-right: 6px solid #fff;     border-bottom: 6px solid transparent;     left: 10px;     top: 11px;     left: -6px; } 

Created my own .sub-menu class to apply to the 2-level drop down menus, this way we can position them next to our menu items. Also modified the arrow to display it on the left of the submenu group.

Demo

like image 160
Andres Ilich Avatar answered Oct 15 '22 20:10

Andres Ilich