2017-09-13 129 views
0

在移動設備上或當我調整瀏覽器大小時,導航欄下拉菜單不會在點擊時下降。我已經把導航條碼放在這裏來詳細說明我的問題。在此先感謝您的幫助!導航欄菜單下拉不起作用(點擊時不會下拉)

<nav class="navbar navbar-default navbar-fixed-top"> 
    <div class="container-fluid"> 
    <div class="navbar-header"> 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="myNavbar"> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
     </button> 
    </div> 
    <div class="collapse navbar-collapse" id="myNavbar"> 
    <ul class="nav navbar-nav navbar-right"> 
     <li><a href="#home">Home</a></li> 
     <li><a href="#about">About</a></li> 
     <li><a href="#portfolio">Portfolio</a></li> 
     <li><a href="#contact">Contact</a></li> 
    </ul> 
    </div> 
</div> 
</nav> 
+0

這是引導?如果答案是肯定的,那麼你是否在編寫腳本來使組件起作用? –

回答

1

兄弟你剛纔錯過了data-target一個#認爲這是如何工作的。

改變這一行

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="myNavbar"> 

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 

check the working demo here!

+0

馬克接受,因爲它會幫助別人解決他們的問題:) –

+0

我添加了#但它仍然無法正常工作。 – batman091716

+0

查看我在答案中附加的演示 –

0

它活生生的例子

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 

 

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

 
<nav class="navbar navbar-default navbar-fixed-top"> 
 
    <div class="container-fluid"> 
 
    <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
 
     <span class="icon-bar"></span> 
 
     <span class="icon-bar"></span> 
 
     <span class="icon-bar"></span> 
 
     </button> 
 
    </div> 
 
    <div class="collapse navbar-collapse" id="myNavbar"> 
 
    <ul class="nav navbar-nav navbar-right"> 
 
     <li><a href="#home">Home</a></li> 
 
     <li><a href="#about">About</a></li> 
 
     <li><a href="#portfolio">Portfolio</a></li> 
 
     <li><a href="#contact">Contact</a></li> 
 
    </ul> 
 
    </div> 
 
</div> 
 
</nav>

你只是錯過#上data-target="myNavbar"data-target="#myNavbar