Bootstrap折叠导航栏无法正常工作

时间:2016-11-03 16:39:36

标签: twitter-bootstrap navbar collapse

我正在学习使我的导航栏可折叠。折叠按钮图标可见,但下拉列表不起作用。任何人都可以在此代码中找到错误

<!Doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>PhotoBomb</title>
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
    <link rel="stylesheet" href="css/style.css"/>

</head>
<body>
    <header>
        <nav class="navbar navbar-inverse 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>
                    <a class="navbar-brand" href="#"><img src="images/img1.png" width="60px"/>PhotoBomb</a>
                </div>
                <div id="myNavbar" class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="#"><i class="fa fa-home"></i>Home </a></li>
                        <li><a href="#">About us </a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <div class="jumbotron text-center">
        <h1>Welcome to PhotoBomb</h1>
        <p>Enhance your memories with the best quality possible</p>
    </div>

</body>

</html>

1 个答案:

答案 0 :(得分:1)

似乎您忘记添加js个文件,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

以下是工作示例,这应该有所帮助:

<!Doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>PhotoBomb</title>
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
    <link rel="stylesheet" href="css/style.css"/>

</head>
<body>
    <header>
        <nav class="navbar navbar-inverse 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>
                    <a class="navbar-brand" href="#"><img src="images/img1.png" width="60px"/>PhotoBomb</a>
                </div>
                <div id="myNavbar" class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="#"><i class="fa fa-home"></i>Home </a></li>
                        <li><a href="#">About us </a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <div class="jumbotron text-center">
        <h1>Welcome to PhotoBomb</h1>
        <p>Enhance your memories with the best quality possible</p>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.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>