twitter-bootstrap bootstrap 可折叠导航栏开始打开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24113305/
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-10-21 20:55:40  来源:igfitidea点击:

bootstrap collapsible navbar starts open

jqueryhtmltwitter-bootstrap

提问by user3721031

I am working on a website with bootstrap, this is the code relative to the navbar

我正在一个带有引导程序的网站上工作,这是相对于导航栏的代码

<nav id="navi" role="navigation" class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" class="navbar-toggle"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="#" class="navbar-brand">Brand</a>
    </div>
    <div id="bs-example-navbar-collapse-1" class="collapse-navbar-collapse">
      <ul class="nav navbar-nav">
        <li><a href="#" class="active">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Gallery</a></li>
        <li><a href="#">Promotion</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

it look very well both on desktop and on mobile, but the problem is that on mobile, the #bs-example-navbar-collapse-1 element starts open!! so that means that basically I need to press the three lines button 2 times to close it (first click basically re-opens the collapsible)

它在桌面和移动设备上看起来都很好,但问题是在移动设备上,#bs-example-navbar-collapse-1 元素开始打开!!所以这意味着基本上我需要按三行按钮 2 次才能关闭它(第一次点击基本上会重新打开可折叠的)

Anyone had the same issue? Thanks in advance.

有人遇到过同样的问题吗?提前致谢。

回答by joshhunt

Try

尝试

<div id="bs-example-navbar-collapse-1" class="collapse-navbar collapse">

and see if that works. I'm pretty sure it should be two classes like "collapse-navbar collapse" not "collapse-navbar-collapse"

看看这是否有效。我很确定它应该是两个类,例如“collapse-navbar collapse”而不是“collapse-navbar-collapse”

回答by Anthony Chu

<div id="bs-example-navbar-collapse-1" class="collapse-navbar-collapse">

In the above div, classes should be defined as class="collapse navbar-collapse". The collapseclass is responsible for initially hiding the nav bar on small screens.

在上面的 div 中,类应该定义为class="collapse navbar-collapse". 该collapse班负责最初隐藏在小屏幕上的导航栏。