Twitter Bootstrap-导航栏内部但导航折叠外部的下拉菜单 [英] Twitter Bootstrap - dropdowns inside navbar but outside nav-collapse

查看:61
本文介绍了Twitter Bootstrap-导航栏内部但导航折叠外部的下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向导航栏添加一个下拉菜单,但是请确保在将浏览器调整为较窄的宽度时,该下拉菜单在导航栏中保持可见,并且不包含在导航折叠中.

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.

以下html可以正常工作.但是,当页面调整大小时,下拉菜单将放到下一行,并且导航栏中的显示会展开,这给我留下了非常深的导航栏.

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.

我正在调用bootstrap-collapse.js和bootstrap-dropdown.js.

I'm calling bootstrap-collapse.js and 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>

推荐答案

根据马克·奥托(Mark Otto),引导程序的开发者之一:

According to Mark Otto, one of the bootstrap's developers:

导航栏中.nav内的所有下拉菜单均会受到影响.目前,我们没有提供防止这种行为的方法.

All dropdowns within the .nav in the navbar will be affected. Currently we don't offer a way to prevent this behavior.

但是,在折叠的导航栏中可能会有未折叠的下拉菜单.您可以通过以下三种方式之一来完成此任务:

However, it is possible to have an uncollapsed dropdown in a collapsed navbar. You can accomplish this in one of three ways:

  1. 在下拉菜单(data-no-collapse="true")中添加数据属性,以修复响应式选择器.
  2. 替换下拉菜单的类(class="dropdown-menu-no-collapse"),从头开始重新构建其样式.
  3. 在下拉菜单(class="dropdown-menu no-collapse)中添加另一个类以覆盖响应样式.
  1. Add a data attribute to the dropdown (data-no-collapse="true") to fix the responsive selectors.
  2. Replace the dropdown’s class (class="dropdown-menu-no-collapse") to rebuild its styles from the ground up.
  3. Add another class to the dropdown (class="dropdown-menu no-collapse) to override the responsive styles.

我写了一篇博客文章解释了该怎么做.第一种方法需要编辑bootstrap-responsive.css,第二种方法需要更改bootstrap.css.对于第三种方法,您不必更改任何引导程序的CSS,但是很难维护.

I wrote a blog post that explains what to do. The first method requires editing bootstrap-responsive.css, and the second requires changing bootstrap.css. You don't have to change any of the bootstrap's CSS for the third method, but it's pretty hard to maintain.

这篇关于Twitter Bootstrap-导航栏内部但导航折叠外部的下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆