Bootstrap 3 is still at RC, but I was just trying to implement it. I couldn't figure out how to put a sub menu class. Even there is no class in css and even the new docs don't say anything about it
It was there in 2.x with class name as dropdown-submenu
This question is related to
css
twitter-bootstrap
twitter-bootstrap-3
submenu
@skelly solution is good but will not work on mobile devices as the hover state won't work.
I have added a little bit of JS to get the BS 2.3.2 behavior back.
PS: it will work with the CSS you get there: http://bootply.com/71520 though you can comment the following part:
CSS:
/*.dropdown-submenu:hover>.dropdown-menu{display:block;}*/
JS:
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
// Avoid following the href location when clicking
event.preventDefault();
// Avoid having the menu to close when clicking
event.stopPropagation();
// If a menu is already open we close it
$('ul.dropdown-menu [data-toggle=dropdown]').parent().removeClass('open');
// opening the one you clicked on
$(this).parent().addClass('open');
});
The result can be found on my WordPress theme (Top of the page): http://shprinkone.julienrenaux.fr/
Shprink's code helped me the most, but to avoid the dropdown to go off-screen i updated it to:
JS:
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
// Avoid following the href location when clicking
event.preventDefault();
// Avoid having the menu to close when clicking
event.stopPropagation();
// If a menu is already open we close it
$('ul.dropdown-menu [data-toggle=dropdown]').parent().removeClass('open');
// opening the one you clicked on
$(this).parent().addClass('open');
var menu = $(this).parent().find("ul");
var menupos = $(menu).offset();
if (menupos.left + menu.width() > $(window).width()) {
var newpos = -$(menu).width();
menu.css({ left: newpos });
} else {
var newpos = $(this).parent().width();
menu.css({ left: newpos });
}
});
CSS: FROM background-color: #eeeeee TO background-color: #c5c5c5 - white font & light background wasn't looking good.
.nav .open > a,
.nav .open > a:hover,
.nav .open > a:focus {
background-color: #c5c5c5;
border-color: #428bca;
}
I hope this helps people as much as it did for me!
But i hope Bootstrap add the subs feature back ASAP.
I make another solution for dropdown. Hope this is helpfull Just add this js script
<script type="text/javascript"> jQuery("document").ready(function() {
jQuery("ul.dropdown-menu > .dropdown.parent").click(function(e) {
e.preventDefault();
e.stopPropagation();
if (jQuery(this).hasClass('open2'))
jQuery(this).removeClass('open2');
else {
jQuery(this).addClass('open2');
}
});
}); < /script>
<style type="text/css">.open2{display:block; position:relative;}</style>
Until today (9 jan 2014) the Bootstrap 3 still not support sub menu dropdown.
I searched Google about responsive navigation menu and found this is the best i though.
It is Smart menus http://www.smartmenus.org/
I hope this is the way out for anyone who want navigation menu with multilevel sub menu.
update 2015-02-17 Smart menus are now fully support Bootstrap element style for submenu. For more information please look at Smart menus website.
Comment to Skelly's really helpful workaround: in Bootstrap-sass 3.3.6, utilities.scss, line 19: .pull-left
has float:left !important
. Since that, I recommend to use !important in his CSS as well:
.dropdown-submenu.pull-left {
float:none !important;
}
I bumped with this issue a few days ago. I tried many solutions and none really worked for me on the end i ended up creating an extenion/override of the dropdown code of bootstrap. It is a copy of the original code with changes to the closeMenus function.
I think it is a good solution since it doesn't affects the core classes of bootstrap js.
You can check it out on gihub: https://github.com/djokodonev/bootstrap-multilevel-dropdown
Source: Stackoverflow.com