Bootstrap 4折叠导航栏无法正常工作

时间:2017-08-22 10:40:59

标签: html css twitter-bootstrap

Bootstrap4中的折叠导航栏出现问题。

<nav class="navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse">
      <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <a class="  navbar-brand" href="#myCarousel">
        <img src="image/logo.svg" height="50">
      </a>
      <div class="collapse navbar-collapse" id="navbarCollapse">
        <ul class="navbar-nav nav mr-auto">
           <li class="nav-item">
            <a class="nav-link" href="#2"  data-toggle="collapse" data-target=".navbar-collapse.show">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#3"  data-toggle="collapse" data-target=".navbar-collapse.show">About</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#4"  data-toggle="collapse" data-target=".navbar-collapse.show">Contact</a>
          </li>
        </ul>

      </div>
    </nav>

当然,我已经为其他元素添加了正确的ID,例如:

<div class="container marketing" id="2">

菜单不起作用。当我点击导航栏的元素时,菜单关闭但不会移动到右侧站点。

删除折叠的属性时:

data-toggle="collapse" data-target=".navbar-collapse.show"

菜单不会在点击时关闭,而是移动到正确的网站。

谢谢:)

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

	<nav class="navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse">
      <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <a class="  navbar-brand" href="#myCarousel">
        <img src="image/techNET.svg" height="50">
      </a>
      <div class="collapse navbar-collapse" id="navbarCollapse">
        <ul class="navbar-nav nav mr-auto">
           <li class="nav-item">
            <a class="nav-link" href="#2"  data-toggle="collapse" data-target=".navbar-collapse.show">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#3"  data-toggle="collapse" data-target=".navbar-collapse.show">About</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#4">Contact</a>
          </li>
        </ul>
       
      </div>
    </nav>
&#13;
&#13;
&#13;