菜单没有在navbar-toggle bootstrap中折叠

时间:2017-11-08 19:15:01

标签: jquery navbar

使用HTML5 CSS3 bootstrap和jquery

浏览器调整大小时,

Bootstrap导航栏菜单不会崩溃 我已经检查了html,并且我使用了最新的jquery版本

通过很多其他帖子搜索想法,并尝试了很多东西,但没有快乐

我希望有人可以提供帮助

代码如下

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-2.1.3.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="navDiv" class="navDiv">
    <nav class="navbar navbar-default navbar-fixed-top navbar-inverse">

        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navDiv"
                        aria-expanded="false">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <!--<a class="navbar-brand" href="about.html">About the project</a>-->
            </div>
            <div class="navbar-header navDiv">
                <!--<a class="navbar-brand" href="#"><img src="images/revive_logo_small.png"></a>-->
            </div>
            <div id="myNavbar">
            <ul class="nav navbar-nav">
                <li><a class="nav-item nav-link active" href="#">| Home |</a></li>
                <li><a class="nav-item nav-link" href="#">| Hypno |</a></li>
                <li><a class="nav-item nav-link" href="#">| NLP |</a></li>
                <li><a class="nav-item nav-link" href="#">| Coaching |</a></li>
                <li><a class="nav-item nav-link" href="#">| About June |</a></li>
                <li><a class="nav-item nav-link" href="#">| Contact |</a></li>
            </ul>
            </div>
        </div>
    </nav>
</div>
<div id="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-5">
                    <img src="images/revive_logo_medium.png" class="me" alt="June">
                    <br>

                </div><!-- end 4 column div -->
                <div class="col-sm-7">
                </div><!-- end 8 column div -->
            </div>
        </div><!-- end full width div -->
    </div>
</div><!--</ content div> -->


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

</body>


</html>

1 个答案:

答案 0 :(得分:0)

您必须在div-container'div id =“myNavbar”'上添加一个类(class =“collapse navbar-collapse”)。 此外,您必须将数据切换更改为“#myNavbar”,因为此div容器包含您的菜单项。 此外,您必须添加bootstrap.js作为资源。

它必须看起来像:

<div id="navDiv" class="navDiv">
<nav class="navbar navbar-default navbar-fixed-top navbar-inverse">

    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar"
                    aria-expanded="false">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <!--<a class="navbar-brand" href="about.html">About the project</a>-->
        </div>
        <div class="navbar-header navDiv">
            <!--<a class="navbar-brand" href="#"><img src="images/revive_logo_small.png"></a>-->
        </div>
        <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav">
            <li><a class="nav-item nav-link active" href="#">| Home |</a></li>
            <li><a class="nav-item nav-link" href="#">| Hypno |</a></li>
            <li><a class="nav-item nav-link" href="#">| NLP |</a></li>
            <li><a class="nav-item nav-link" href="#">| Coaching |</a></li>
            <li><a class="nav-item nav-link" href="#">| About June |</a></li>
            <li><a class="nav-item nav-link" href="#">| Contact |</a></li>
        </ul>
        </div>
    </div>
</nav>

JSFiddle link