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

时间:2016-08-07 18:34:48

标签: twitter-bootstrap twitter-bootstrap-3 navbar collapse

this is the image with probelem 我是学生,我遇到了引导问题。我有一个问题,在bootstrap中创建崩溃我会尝试一切,但它仍然无法正常工作,请帮助。

这是我的代码:

<!DOCTYPE html>
<html lang="en">

 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Anything</title>
  <meta name="description" content="">
  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <!-- Optional theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
 </head>

 <style>
  body {
  padding-top: 51px;
}
@media (max-width: 979px) {
  body {
    padding-top: 0px;
	font-family: 'Lato', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  }
}
 </style>
 
 <body>
  
  <!-- NavBar -->
   
   <nav class="navbar navbar-inverse navbar-fixed-top" id="my-navbar">
    <div class="container">
	 <div class="navbar-header">
	  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav-collapse">
	   <span class="icon-bar"></span>
	   <span class="icon-bar"></span>
	   <span class="icon-bar"></span>
	   <span class="icon-bar"></span>
	  </button>
	  
	  <a href="#" class="navbar-brand">Anything</a>
	 </div>
	 <div class="collapse navbar-collapse" id="nav-collapse">
	   <ul class="nav navbar-nav"> 
	    <li><a href="#">HOME</a></li>
		<li><a href="#">COURCES</a></li>
		<li><a href="#">THEMES</a></li>
		<li><a href="#">EXTRA</a></li>
	   </ul>
	 </div>
	</div>
   </nav>
 </body>
</html>

1 个答案:

答案 0 :(得分:4)

您需要在Bootstrap之前加载JQuery库,因为JQuery是Bootstrap javascript文件的依赖项。要解决这两行代码的问题:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>

暂且不说:所有Bootstrap Javascript插件都需要JQuery。 navbar css功能使用Bootstrap中的collapse Javascript插件,因此需要JQuery。