我正在使用 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 和引导样式表:
<?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 上一样工作。这样,当我使窗口变小时,当您单击它时,汉堡菜单会立即起作用。
下面的代码应该是。
data-toggle="collapse"
而不是data-toggle="dropdown"