Bootstrap 导航栏折叠按钮未显示

jljoyd4f  于 12个月前  发布在  Bootstrap
关注(0)|答案(4)|浏览(188)

我做了一个应用程序与 Bootstrap ,我有一个导航栏,但由于某种原因,当我调整页面的链接消失,但切换按钮不显示。
这是我的导航栏:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <div class="navbar-brand">title</div>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav navbar-right">
          <li>one</li>
          <li>two</li>
          <li>three</li>
          <li>four</li>
      </ul>
  </div>
</nav>

字符串
任何帮助解决这个问题将不胜感激。

iq0todco

iq0todco1#

您的代码中目前没有切换按钮。请尝试在折叠之前和导航栏标题之后放置以下内容:

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>

字符串
http://www.w3schools.com/bootstrap/bootstrap_navbar.asp

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Page 1-1</a></li>
            <li><a href="#">Page 1-2</a></li>
            <li><a href="#">Page 1-3</a></li>
          </ul>
        </li>
        <li><a href="#">Page 2</a></li>
        <li><a href="#">Page 3</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>
  
<div class="container">
  <h3>Collapsible Navbar</h3>
  <p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
  <p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>

xqnpmsa8

xqnpmsa82#

你没有添加一个切换按钮,我可以看到在你的代码

<div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <div class="navbar-brand">title</div>
 </div>

字符串
有关详细信息,请参阅Navbar文档( Bootstrap )

k2arahey

k2arahey3#

在我的情况下,我使用bootstrap5,但类我使用旧版本,更改代码后,如下所示,它为我工作,通过去BS5 W2Schools:

<nav class="navbar navbar-expand-sm bg-dark">
    <div class="container-fluid">
        <a href="#" class="navbar-brand">Recipe Book</a>
        <ul class="nav navbar-nav">
            <li class="nav-item" routerLinkActive="active">
                <a class="nav-link" routerLink="/recipes">Recipes</a>
            </li>
            <li class="nav-item" routerLinkActive="active">
                <a class="nav-link" routerLink="/shopping-list">Shopping List</a>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="nav-item dropdown" appDropdown>
                <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Manage<span class="caret"></span></a>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="#">Save Data</a></li>
                    <li><a class="dropdown-item" href="#">Fetch Data</a></li>
                </ul>
            </li>
        </ul>
    </div>
</nav>

字符串
参考:https://www.w3schools.com/bootstrap5/tryit.asp?filename=trybs_navbar_dropdown&stacked=h

fcy6dtqo

fcy6dtqo4#

对我来说,愚蠢的事情是,我应该使用bootstrap 3而不是bootstrap5,这是我一开始安装的。
无论我做了什么,类collapsediv就是没有出现。
所以我换了bootstrap 3,一切都开始正常工作了!

相关问题