带有Bootstrap 3.0的导航栏中的多个折叠按钮 [英] Multiple Collapse buttons in navbar with Bootstrap 3.0
问题描述
我正在使用Bootstrap 3.0来显示带有一些链接和搜索字段的导航栏. 当我转到移动版"时,我有一个折叠导航栏并显示所有内容的按钮:链接和搜索字段.现在,我需要两个按钮,一个按钮仅折叠导航栏的链接,另一个按钮仅折叠搜索字段.我该怎么做?
I'm using Bootstrap 3.0 to show a navbar with some links and a search field. When i go to "mobile version" i have a button that collapses the navbar and show all the content: the links and the search field. Now I need two buttons, one to collapse only the links of the navbar and the other button to collapse only the search field. How can i make this?
推荐答案
将链接和搜索表单分成两个navbar-collapse
元素,并让每个按钮定位对应的一个:
Separate the links and the search form into two navbar-collapse
elements and have each button target the corresponding one:
样本标记:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#search">Toggle search</button>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#links">Toggle links</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<ul class="collapse navbar-collapse nav navbar-nav" id="links">
<!--Links go here-->
</ul>
<div class="collapse navbar-collapse" id="search">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</nav>
然后,您只需将.navbar-nav
和.navbar-collapse
之间的样式冲突,只需将其添加到CSS中即可:
You would then just need to fix some conflicting styles between .navbar-nav
and .navbar-collapse
by adding this to your CSS:
@media (max-width:767px) {
.navbar-nav.navbar-collapse {
margin-left: 0;
margin-right: 0;
padding-left: 0;
padding-right: 0;
}
}
这是 演示小提琴
Here's a demo fiddle
这篇关于带有Bootstrap 3.0的导航栏中的多个折叠按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!