Html 在 Bootstrap 3.3.2 中更改导航栏断点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28659556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:33:59  来源:igfitidea点击:

Change Navbar breakpoint in Bootstrap 3.3.2

htmlcsstwitter-bootstrap

提问by Matt Hall

I'm putting together a rough navbar using Twitter bootstrap.

我正在使用 Twitter 引导程序组合一个粗略的导航栏。

TopNav1

顶部导航1

There's a breakpoint at which the width of the device will cause the navbar items to collapse and show a menu button instead:

有一个断点,设备的宽度将导致导航栏项目折叠并显示菜单按钮:

TopNav3

顶部导航3

How can I change the breakpoint so the navbar collapses sooner? At the moment its able to break on to a new line when it comes up against the logo, which doesn't look too great:

如何更改断点以便导航栏更快地折叠?目前它能够在遇到标志时换行,这看起来不太好:

TopNav2

顶部导航2

I've tried a fix detailed here, but it seemed to break the collapsed menu (couldn't expand it again afterwards).

我已经尝试了一个详细的修复here,但它似乎打破了折叠菜单(之后无法再次展开它)。

Here's the html:

这是html:

    <!-- navigation -->
    <div class="navbar navbar-default navbar-static-top">
        <div class="container-fluid">
            <div class="navbar-header">

                <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <a class="navbar-brand" href="#"><img class="ManeEventLogo" src="/img/ManeEventLogoWhite-Sm.png"></a>
            </div>

            <div class="collapse navbar-collapse navbar-responsive-collapse">

                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/index.php">HOME</a>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">SERVICES <span class="caret"></span></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="/services/cutting-styling/index.php">Cutting & Styling</a></li>
                                <li><a href="/services/coloring/index.php">Coloring</a></li>                                
                                <li><a href="/services/hair-straightening-relaxing/index.php">Permanent Hair Straightening & Relaxing</a></li>
                                <li><a href="/services/balmain-hair-extensions/index.php">Balmain Hair Extensions</a></li>
                            </ul>
                    <li>
                        <a href="/wedding-day/index.php">WEDDING DAY</a>
                    </li>
                    <li>
                        <a href="/expertise-team/index.php">THE EXPERTISE TEAM</a>
                    </li>
                    <li>
                        <a href="/photo-gallery/index.php">PHOTO GALLERY</a>
                    </li>
                    <li>
                        <a href="/blog/index.php">BLOG</a>
                    </li>
                </ul>

            </div>
        </div>
    </div>

回答by kybernaut.cz

Which version of bootstrap are you using? 3.1? Anyway, I need as well your css to help you to fix it, but generally:

您使用的是哪个版本的引导程序?3.1?无论如何,我也需要你的 css 来帮助你修复它,但通常:

@media (max-width: 1200px) {
    .navbar-header {
        float: none;
    }
    .navbar-left,.navbar-right {
        float: none !important;
    }
    .navbar-toggle {
        display: block;
    }
    .navbar-collapse {
        border-top: 1px solid transparent;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    }
    .navbar-fixed-top {
        top: 0;
        border-width: 0 0 1px;
    }
    .navbar-collapse.collapse {
        display: none!important;
    }
    .navbar-nav {
        float: none!important;
        margin-top: 7.5px;
    }
    .navbar-nav>li {
        float: none;
    }
    .navbar-nav>li>a {
        padding-top: 10px;
        padding-bottom: 10px;
    }
    .collapse.in{
        display:block !important;
    }
   .navbar-nav .open .dropdown-menu {
       position: static;
       float: none;
       width: auto;
       margin-top: 0;
       background-color: transparent;
       border: 0;
       -webkit-box-shadow: none;
       box-shadow: none;
    }
}

The max width is the breakpoint. Copied from Bootply(with demo included there).

最大宽度是断点。从Bootply复制(其中包含演示)。

回答by don_Bigote

The following code will create a navbar breakpoint at 991 px. The .navbar-nav class is important if you have more than a few links in your navbar.

以下代码将在 991 像素处创建一个导航栏断点。如果您的导航栏中有多个链接,.navbar-nav 类很重要。

@media (max-width: 991px) {
  .navbar-header {
      float: none;
  }
  .navbar-left,.navbar-right {
      float: none !important;
  }
  .navbar-toggle {
      display: block;
  }
  .navbar-collapse {
      border-top: 1px solid transparent;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  }
  .navbar-fixed-top {
      top: 0;
      border-width: 0 0 1px;
  }
  .navbar-collapse.collapse {
      display: none!important;
  }
  .navbar-nav {
      float: none!important;
      margin-top: 7.5px;

      max-height: 300px;
      overflow-y: scroll!important;
  }
  .navbar-nav>li {
      float: none;
  }
  .navbar-nav>li>a {
      padding-top: 10px;
      padding-bottom: 10px;
  }
  .collapse.in{
      display:block !important;
  }

}