Bootstrap 引导折叠导航栏不工作

nbewdwxp  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(216)

我正在学习如何使导航栏可折叠。折叠按钮图标是可见的,但下拉菜单不起作用。有人能找到此代码中的错误吗

<!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>
9wbgstp7

9wbgstp71#

您似乎忘记添加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>

相关问题