引导3仍然在RC,但我只是试图实现它。我不知道怎么放一个子菜单类。甚至css中没有类,甚至新的文档也没有提到它
2分钟就到了。用类名作为下拉菜单
引导3仍然在RC,但我只是试图实现它。我不知道怎么放一个子菜单类。甚至css中没有类,甚至新的文档也没有提到它
2分钟就到了。用类名作为下拉菜单
当前回答
评论Skelly的真正有用的解决方案:在Bootstrap-sass 3.3.6,实用程序。Scss,第19行:.pull-left有float:left !重要。因此,我建议在他的CSS中也使用!important:
.dropdown-submenu.pull-left {
float:none !important;
}
其他回答
直到今天(2014年1月9日)Bootstrap 3仍然不支持子菜单下拉。
我搜索了谷歌关于响应式导航菜单,发现这是最好的。
它是智能菜单http://www.smartmenus.org/
我希望这是谁想要导航菜单多级子菜单的出路。
智能菜单现在完全支持子菜单的Bootstrap元素样式。欲了解更多信息,请查看智能菜单网站。
随着Bootstrap 5,现在很容易实现下拉子菜单,而不需要使用任何javascript代码,这要感谢新的autoClose选项和dropend类。
现场演示:https://jsfiddle.net/b038kc2y/
.dropdown-menu .dropdown-menu {
top: -.5rem !important;
}
<div class="dropdown m-5">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<li class="dropend">
<a class="dropdown-item" href="#" id="dropdownSubMenuLink" data-bs-toggle="dropdown" aria-expanded="false">Submenu Action</a>
<ul class="dropdown-menu" aria-labelledby="dropdownSubMenuLink">
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
在2022年的Bootstrap 5中,这个GitHub回购中的JS代码是子菜单的最终解决方案:https://github.com/dallaslu/bootstrap-5-multi-level-dropdown。
这是我的解决方案(我使用bootstrap 5):
HTML
<div class="btn-group dropend" role="group">
<button id="submenu" type="button" class="dropdown-item dropdown-toggle submenu" data-bs-toggle="dropdown" aria-expanded="false">
Menu Item
</button>
<div class="dropdown-menu" aria-labelledby="submenu">
<a class="dropdown-item">Submenu</a>
</div>
</div>
JS
$('.submenu').click(function(e){
e.preventDefault();
e.stopPropagation();
});
我给出了下拉的另一个解。希望这对你有帮助 只需添加这个js脚本
<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>