2016-08-19 96 views
2

我已經創建了一個Navbar Header的頂部導航,其中有一個帶有下拉子菜單和插入符號的4個主要鏈接。用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"> 
 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
 
    <title>Bootstrap with HTML</title> 
 

 
    <!-- Bootstrap --> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 

 
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> 
 
    </script> 
 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
 
    <!--[if lt IE 9]> 
 
       <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> 
 
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
 
    <![endif]--> 
 

 
</head> 
 

 
<body> 
 

 
    <!-- Navbar with Dropdown Menus --> 
 
    <!-- Start Navbar Top --> 
 
    <nav class="navbar navbar-default"> 
 
    <div class="container"> 
 
     <!-- Toggle buttons snippet - This will define the toggle buttons of the navigation when the screen gets smaller --> 
 
     <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> 
 
     <span class="icon-bar"></span> 
 
     </button> 
 
     <!-- End of Toggle button snippet --> 
 

 
     <!-- The Site Name or Brand name snippet --> 
 
     <a class="navbar-brand" href="www.youtube.com" target="_blank">The Bootstrap Site with HTML</a> 
 
     <!-- End of brand name snippet --> 
 

 
     <!-- The below defines the navigation links in the Navbar. From this point you can create the links for the navigation --> 
 
     <div class="navbar-collapse collapse"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
      <li><a href="#">Home</a> 
 
      </li> 
 
      <li><a href="#">Technologies</a> 
 
      </li> 
 
      <li><a href="#">Partners</a> 
 
      </li> 
 
      <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="drop-down">Products <b class="caret"></b></a> 
 
      <ul class="dropdown-menu"> 
 
       <li><a href="#">SaaS</a> 
 
       </li> 
 
       <li><a href="#">PaaS</a> 
 
       </li> 
 
       <li><a href="#">Cloud</a> 
 
       </li> 
 
       <li><a href="#">IofT</a> 
 
       </li> 
 
      </ul> 
 
      </li> 
 
     </ul> 
 
     </div> 
 
     <!--End of the navigation links in the Navbar --> 
 

 
    </div> 
 
    </nav> 
 
    <!-- End of Navbar Top --> 
 

 

 
</body> 
 

 
</html>

+0

它爲我在鉻52上工作。您使用哪種瀏覽器? – bazi

回答

2

data-toggle="drop-down"應該data-toggle="dropdown",這一切現在工作正常。

看看並讓我知道您的反饋。謝謝!

<!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"> 
 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
 
    <title>Bootstrap with HTML</title> 
 

 
    <!-- Bootstrap --> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 

 
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> 
 
    </script> 
 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
 
    <!--[if lt IE 9]> 
 
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> 
 
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
 
<![endif]--> 
 

 
</head> 
 

 
<body> 
 

 
    <!-- Navbar with Dropdown Menus --> 
 
    <!-- Start Navbar Top --> 
 
    <nav class="navbar navbar-default"> 
 
    <div class="container"> 
 
     <!-- Toggle buttons snippet - This will define the toggle buttons of the navigation when the screen gets smaller --> 
 
     <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> 
 
     <span class="icon-bar"></span> 
 
     </button> 
 
     <!-- End of Toggle button snippet --> 
 

 
     <!-- The Site Name or Brand name snippet --> 
 
     <a class="navbar-brand" href="www.youtube.com" target="_blank">The Bootstrap Site with HTML</a> 
 
     <!-- End of brand name snippet --> 
 

 
     <!-- The below defines the navigation links in the Navbar. From this point you can create the links for the navigation --> 
 
     <div class="navbar-collapse collapse"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
      <li><a href="#">Home</a> 
 
      </li> 
 
      <li><a href="#">Technologies</a> 
 
      </li> 
 
      <li><a href="#">Partners</a> 
 
      </li> 
 
      <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Products <b class="caret"></b></a> 
 
      <ul class="dropdown-menu"> 
 
       <li><a href="#">SaaS</a> 
 
       </li> 
 
       <li><a href="#">PaaS</a> 
 
       </li> 
 
       <li><a href="#">Cloud</a> 
 
       </li> 
 
       <li><a href="#">IofT</a> 
 
       </li> 
 
      </ul> 
 
      </li> 
 
     </ul> 
 
     </div> 
 
     <!--End of the navigation links in the Navbar --> 
 

 
    </div> 
 
    </nav> 
 
    <!-- End of Navbar Top --> 
 

 

 
</body> 
 

 
</html>

+0

這工作。謝謝你的幫助。 – ChiranSJ

0

改變這一點:

<a href="#" class="dropdown-toggle" data-toggle="drop-down">Products <b class="caret"></b></a> 

此:

<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Products <b class="caret"></b></a> 
+0

這工作。謝謝你的幫助。 – ChiranSJ

2

試試這個

<!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"> 
 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
 
    <title>Bootstrap with HTML</title> 
 

 
    <!-- Bootstrap --> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 

 
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> 
 
    </script> 
 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
 
    <!--[if lt IE 9]> 
 
       <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> 
 
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
 
    <![endif]--> 
 

 
</head> 
 

 
<body> 
 
     <!-- Navbar with Dropdown Menus --> 
 
     <!-- Start Navbar Top --> 
 
     <nav class="navbar navbar-default"> 
 
      <div class="container"> 
 
       <!-- Toggle buttons snippet - This will define the toggle buttons of the navigation when the screen gets smaller --> 
 
      <div class="navbar-header"> 
 
       
 
\t  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
 
\t   <span class="sr-only">Toggle navigation</span> 
 
\t   <span class="icon-bar"></span> 
 
\t   <span class="icon-bar"></span> 
 
\t   <span class="icon-bar"></span> 
 
\t  </button> 
 
       
 
       <a class="navbar-brand" href="www.youtube.com" target="_blank">The Bootstrap Site with HTML</a> 
 
      </div> 
 
      <!-- End of Toggle button snippet --> 
 

 
       <!-- The Site Name or Brand name snippet --> 
 
       <!-- End of brand name snippet --> 
 

 
       <!-- The below defines the navigation links in the Navbar. From this point you can create the links for the navigation --> 
 
       <div class="navbar-collapse collapse"> 
 
        <ul class="nav navbar-nav navbar-right"> 
 
         <li ><a href="#">Home</a></li> 
 
         <li ><a href="#">Technologies</a></li> 
 
         <li ><a href="#">Partners</a></li> 
 
         <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Products <b class="caret"></b></a> 
 
          <ul class="dropdown-menu"> 
 
          <li><a href="#">SaaS</a></li> 
 
          <li><a href="#">PaaS</a></li> 
 
          <li><a href="#">Cloud</a></li> 
 
          <li><a href="#">IofT</a></li> 
 
         </ul> 
 
         </li> 
 
        </ul> 
 
       </div> 
 
       <!--End of the navigation links in the Navbar --> 
 

 
       </div> 
 
      </nav> 
 
      <!-- End of Navbar Top --> 
 

 

 

 
</body> 
 

 
</html>

+0

這工作。謝謝你的幫助。 – ChiranSJ

相關問題