Bootstrap导航栏汉堡包菜单无法打开

时间:2016-02-15 08:14:32

标签: javascript html css twitter-bootstrap hamburger-menu

我正在使用getbootstrap.com的Bootstrap 3.3.5版。我从他们的网站(https://getbootstrap.com/components/#navbar)复制了导航栏代码。我调整了这段代码,使它看起来像我希望它看起来。这就是它现在的样子:

<?php
/**
 * Created by PhpStorm.
 * User: Olivier
 * Date: 2/10/2016
 * Time: 10:41 AM
 */
?>
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="dropdown" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="index.php">Home</a></li>
        <li><a href="about.php">About</a></li>
        <li><a href="#portfolio">Portfolio</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="contact.php">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

我在这段代码中包含了JQuery和bootstrap样式表:

<?php

/**
 * Created by PhpStorm.
 * User: Olivier
 * Date: 2/10/2016
 * Time: 10:30 AM
 */
?>
<html>
<head>
    <title>EquiRent</title>
    <!-- Latest compiled and minified JavaScript -->
    <!--    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>-->

    <!--
       **Including bootstrap
       -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css">
    <!-- Optional theme -->
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap-theme.min.css">
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="../static/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

导航栏看起来很好,一切正常但只要我让页面足够小,以便汉堡包菜单会自动显示并点击它,没有任何反应。

我希望导航栏能够像https://getbootstrap.com/components/#navbar一样工作。因此,当我将窗口缩小时,汉堡包菜单在您点击它时会自动执行某些操作。

1 个答案:

答案 0 :(得分:6)

嗨,下面的代码应该是。

data-toggle="collapse"代替data-toggle="dropdown"