引导两个导航栏崩溃 [英] Bootstrap two navbars collapsing
问题描述
在引导程序中,我想在彼此下方有两个导航栏. 我的想法: 导航栏1有一个品牌:主菜单. 导航栏2(在navbar1下方)的品牌为:子菜单.
In bootstrap i want to have two navbars below eachother. My idea: Navbar 1 has a brand: main menu. Navbar 2 (below navbar1) has a brand called: sub menu.
当用户在手机上查看站点时,他/她会看到两个可折叠的导航栏. 用户现在可以选择打开导航栏.菜单或子菜单.
When the user looks at the site on his mobile phone he/she sees two collapsible navbars. The user can now choose wich navbar to open. The menu or the sub menu.
我刚刚在引导网站上复制了标准代码: http://getbootstrap.com/components/#navbar
I just copied the standard code on the bootstrap website: http://getbootstrap.com/components/#navbar
奇怪的是.当我缩小浏览器尺寸时.出现两个折叠的导航栏. 主菜单"和子菜单".当我单击主菜单后面的按钮时,将显示主菜单.就像它应该那样.但是当我按下子菜单(取消折叠)按钮时.主菜单再次打开.不是子菜单.
Strange thing is. When i make my browser small. Two collapsed navbars appear. "Main-menu" and "sub-menu". When i click on the butten behind main menu the main menu appears. Just like it should. But when i press the sub-menu (uncollapse) button. The MAIN-MENU opens again. Not the sub menu.
我只是使用了bootstrap网站上的标准导航栏代码,将其粘贴到了eachoter下并更改了品牌名称. 这里是bootply: http://bootply.com/101690 在移动设备上进行测试,看看导航栏中会发生什么.
I just used the standard navbar code from the bootstrap website in the link pasted those beneath eachoter and changed the brand names. HERE is the bootply: http://bootply.com/101690 Test it on mobile and see what happens in the navbars.
推荐答案
您对两个导航栏使用相同的ID值,更改第二个导航栏的ID和相应的数据目标值:
You use the same id value for both navbar, change the id for the second navbar and the corresponding data-target value:
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">MAIN menu</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">MAIN menu link1</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Sub menu</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Sub menu link1</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
这篇关于引导两个导航栏崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!