我正在尝试为Bootstrap创建一个3级折叠导航栏菜单,但我无法打开第三级。
这是我的两级菜单:
<link href="https://stackpath.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse">
<ul class="nav">
<a class="brand" href="#">Present Ideas</a>
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Help</a></li>
<li class="dropdown" id="accountmenu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Account Settings<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Login</a></li>
<li><a href="#">Register</a></li>
<li class="divider"></li>
<li><a href="#">Logout</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right">
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>
我认为这样的事情会起作用:
<link href="https://stackpath.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Help</a></li>
<li class="dropdown" id="accountmenu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Account Settings<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Login</a></li>
<li class="item-148 dropdown parent">
<a href="/about/learn-more">Learn more <b class="caret-right"></b></a>
<ul class="dropdown-menu">
<li class="item-149"><a href="/about/learn-more/the-software">The Software</a></li>
<li class="item-150"><a href="/about/learn-more/the-project">The Project</a></li>
<li class="item-151"><a href="/about/learn-more/the-leadership">The Leadership</a></li>
<li class="item-152"><a href="/about/learn-more/open-source-matters">Open Source Matters</a></li>
</ul>
</li>
<li class="divider"></li>
<li><a href="#">Logout</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right">
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>
但那不起作用。
答案 0 :(得分:33)
Bootstrap 2.3.x及更高版本支持dropdown-submenu
..
<ul class="dropdown-menu">
<li><a href="#">Login</a></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">More options</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Second level</a></li>
<li><a href="#">Second level</a></li>
<li><a href="#">Second level</a></li>
</ul>
</li>
<li><a href="#">Logout</a></li>
</ul>
答案 1 :(得分:1)
Bootstrap 3删除了对嵌套折叠菜单的原生支持,但是有一种方法可以使用第三方脚本重新启用它。它被称为SmartMenus。这意味着向您的页面添加三个新资源,但它无缝支持Bootstrap 3.x,其中包含嵌套<ul>/<li>
元素和class="dropdown-menu"
元素的多级菜单。它还会自动显示正确的插入符号指示符。
<head>
...
<script src=".../jquery.smartmenus.min.js"></script>
<script src=".../jquery.smartmenus.bootstrap.min.js"></script>
...
<link rel="stylesheet" href=".../jquery.smartmenus.bootstrap.min.css"/>
...
</head>
这是一个演示页:http://vadikom.github.io/smartmenus/src/demo/bootstrap-navbar-fixed-top.html