一尘不染

bootstrap 3导航栏折叠按钮不起作用

css

我在导航栏中做了一些修改,但是现在切换按钮在单击时没有响应。下面是我的代码。我哪里错了??


码:

  <body>
    <div class="navbar-wrapper">
      <div class="container">

        <div class="navbar navbar-default navbar-static-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>
              </button>
              <a class="navbar-brand" href="./index.html">ossoc</a>
            </div>
            <div class="collapse navbar-collapse">
              <ul class="nav navbar-nav navbar-right">
                <button id="loginbutton" type="button" class="btn btn-primary narbar-btn"><i class="glyphicon glyphicon-log-in"></i>Login</button>
                <button type="button" class="btn btn-success navbar-btn"><i class="glyphicon glyphicon-link"></i><a href="./register.jsp">Create account</a></button>
              </ul>
            </div>
          </div>
        </div>

      </div>
    </div>


阅读 337

收藏
2020-05-16

共1个答案

一尘不染

您需要更改此标记

 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar collapse">

改变

data-target=".navbar collapse"

data-target=".navbar-collapse"

原因:的值data-target是关联的nav div的任何类名。在这种情况下

<div class="collapse navbar-collapse">  <-- Look at here
     <ul class="nav navbar-nav navbar-right">
     .....
</div>
2020-05-16