twitter-bootstrap Bootstrap 默认导航栏不会在移动视图中折叠

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

Bootstrap default navbar is not collapsed in mobile view

csstwitter-bootstrapmobilenavbar

提问by Nicola Sansom

So I am new to bootstrap and can't seem to find a solution to fix my problem which is when the mobile view the menu is open when I want it to be collapsed by default.

所以我是引导程序的新手,似乎无法找到解决我的问题的解决方案,即当移动视图菜单打开时,我希望它在默认情况下折叠。

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
   <div class="navbar-header">
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
       <span class="sr-only">Toggle navigation</span>
           <span class="icon-bar"></span>
           <span class="icon-bar"></span>
           <span class="icon-bar"></span>
       </button>

      </div>
      <div class="navbar-collapse collpase">
      <ul class="nav navbar-nav navbar-left">
          <li><a href="#">Home</a></li>
          <li><a href="#">News & Events</a></li>
          <li class="dropdown">
          <a href="#" class ="dropdown-toggle" data-toggle="dropdown">Things to do<b class="caret"></b></a>
        <ul class="dropdown-menu">
              <li><a href="#">Leisure</a></li>
              <li><a href="#">Groups & Activities </a></li>
              <li></li>    
              </ul>      

          </li>
           <li class="dropdown">
          <a href="#" class ="dropdown-toggle" data-toggle="dropdown">Services<b class="caret"></b></a>
        <ul class="dropdown-menu">
              <li><a href="#">Education & Learning</a></li>
              <li><a href="#">Personal Care</a></li>
              <li><a href="#">Police</a></li>
              <li></li>    
              </ul>      

          </li>
          <li><a href="#">Businesses</a></li>
          <li><a href="#">History</a></li>
          <li><a href="#">Discussion Forum</a></li>



          </ul>

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

Example screenshot

示例截图

回答by David Wilkinson

You have the wrong class in the wrapping <div>of the dropdown, should be as follows (there's a typo in yours - "collpase"):

<div>在下拉列表的包装中有错误的类,应如下所示(您的输入错误 - “ collpase”):

<div class="collapse navbar-collapse">

https://jsfiddle.net/2y9edmk1/

https://jsfiddle.net/2y9edmk1/

回答by David Wilkinson

It's a JQuery issue.Check wether the JQuery is included correctly or not.

这是一个 JQuery 问题。检查 JQuery 是否正确包含。

回答by Aukhan

Typo in code

代码中的错别字

<div class="navbar-collapse collpase">

check spelling for collapse

检查拼写是否折叠