Bootstrap下拉菜单未显示

时间:2015-10-23 23:53:42

标签: jquery menu nav dropdown

我在Bootstrap中的下拉菜单似乎没有工作 - 有人能提醒我这个问题吗?现在它显示宽度小于768px的下拉图标,但点击它什么都不做。谢谢!

<header>
    <div class="navbar-wrapper"></div>
        <div class="navbar navbar-default">
            <div class="navbar-inner">
                <div class="container">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" 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>
                        <a class="navbar-brand" href="/"><img src="assets/img/logo.png" alt="Bootstrap to Wordpress"></a>   
                    </div><!-- navbar header -->
                    <div class="navbar-collapse collapse">
                        <ul class="nav navbar-nav navbar-right">
                          <li class="active"><a href="/">Home</a></li>
                          <li><a href="#">About</a></li>
                          <li><a href="#">Portfolio</a></li>
                          <li><a href="#">Contact</a></li>
                        </ul>
                    </div><!-- navbar-collapse -->
                </div><!-- navbar-container -->
            </div><!-- navbar-inner -->
        </div><!-- navbar -->
    </div><!-- navbar-wrapper -->
</header>

身体部分的代码:

<!-- BOOTSTRAP CORE JAVASCRIPT
        Placed at the end of the document so the pages load faster.
========================================================== -->

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

<script src="assets/js/jquery-2.1.4.min.js"></script>

<script src="assets/js/bootstrap.min.js"></script>

<script src="assets/js/main.js"></script>

1 个答案:

答案 0 :(得分:0)

修改导航栏,为其添加一个类似<div id="myNav" class="navbar-collapse collapse">的ID,然后使用data-target调用该ID,即data-target="#myNav"

CodePen工作demo

完整代码:

<nav class="navbar navbar-default navbar-fixed-top" id="navbar">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNav" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/"><img src="assets/img/logo.png" alt="Bootstrap to Wordpress"></a>  
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
         <div id="myNav" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li class="active"><a href="/">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Portfolio</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
      </div><!-- navbar-collapse -->
        </div><!-- /.navbar-collapse -->    
    </div>
</nav>

特定Bootstrap断点的媒体查询。

/* Large Devices, Wide Screens */
@media only screen and (max-width : 1200px) {

}

/* Medium Devices, Desktops */
@media only screen and (max-width : 992px) {

}

/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {

}

/* Extra Small Devices, Phones */ 
@media only screen and (max-width : 480px) {

}

/* Custom, iPhone Retina */ 
@media only screen and (max-width : 320px) {

}