Twitter Bootstrap - 导航栏内的下拉菜单但导航折叠外
我想向导航栏添加一个下拉菜单,但请确保当浏览器调整为更窄的宽度时,下拉菜单在导航栏中保持可见,并且不包含在导航折叠中。
下面的 html 有效。然而,当页面调整大小时,下拉菜单会下降到下一行,并在导航栏中显示展开,从而给我留下一个非常深的导航栏。
我正在调用 bootstrap-collapse.js 和 bootstrap-dropdown.js。
有人有什么想法吗?
<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>
<a class="brand" href="#">Project</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
<div class="container">
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Sharing<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Twitter</a></li>
<li><a href="#">Facebook</a></li>
<li><a href="#">Google+</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
I want to add a dropdown to the navbar, but ensure that when the browser is resized to a narrower width, the dropdown remains visible in the navbar and is not included in the nav-collapse.
The html below works. However, when the page resizes, the dropdown drops onto the next row, and displays expanded in the navbar, leaving me with a very deep navbar.
I'm calling bootstrap-collapse.js and bootstrap-dropdown.js.
Anyone got any ideas?
<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>
<a class="brand" href="#">Project</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
<div class="container">
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Sharing<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Twitter</a></li>
<li><a href="#">Facebook</a></li>
<li><a href="#">Google+</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Bootstrap 开发人员之一 Mark Otto 的说法:
但是,折叠的导航栏中可以有未折叠的下拉菜单。您可以通过以下三种方法之一来完成此操作:
data-no-collapse="true"
) 以修复响应式选择器。class="dropdown-menu-no-collapse"
) 以从头开始重建其样式。class="dropdown-menu no-collapse
) 以覆盖响应式样式。我写了一篇博客文章 解释了要做什么。第一种方法需要编辑
bootstrap-responsive.css
,第二种需要更改bootstrap.css
。对于第三种方法,您不必更改任何 bootstrap 的 CSS,但这非常困难。维持。According to Mark Otto, one of the bootstrap's developers:
However, it is possible to have an uncollapsed dropdown in a collapsed navbar. You can accomplish this in one of three ways:
data-no-collapse="true"
) to fix the responsive selectors.class="dropdown-menu-no-collapse"
) to rebuild its styles from the ground up.class="dropdown-menu no-collapse
) to override the responsive styles.I wrote a blog post that explains what to do. The first method requires editing
bootstrap-responsive.css
, and the second requires changingbootstrap.css
. You don't have to change any of the bootstrap's CSS for the third method, but it's pretty hard to maintain.这是因为容器被填充到右侧或类似的东西。
分别使用 margin-right 和 margin-left : -30px;分别位于最右边和最左边的无序列表上。
不太漂亮,但直到他们修复它......
It's because the container is padded to the right or something like that.
Use margin-right respectively margin-left : -30px; on the rightmost, respectively leftmost unordered list.
Not really pretty, but until they fix it ...