Bootstrap 3:当屏幕缩小时,Navbar不会折叠成hamburguer菜单

时间:2016-04-02 09:07:04

标签: html css twitter-bootstrap

我正在使用Bootstrap 3,由于某种原因,我的navbar菜单没有进入"汉堡包#34;缩小屏幕时的菜单。

我已经检查过我已经包含了JQuery以及Bootstrap Javascript和CSS文件。控制台也不会抛出任何错误。

这是我的代码:

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>My Site</title>

    <script src="https://code.jquery.com/jquery-2.2.2.min.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link href='http://fonts.googleapis.com/css?family=Yesteryear' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <link href="css/thumbnail-gallery.css" rel="stylesheet">

</head>

<body style="background-color:#F0F0F0;">


    <nav class="navbar" role="navigation">
        <div class="container">

            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <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="index.html" style="font-family:YesterYear; font-size:2.9em;">MY SITE</a>
            </div>

            <div class="collapse navbar-collapse pull-right" id="bs-example-navbar-collapse-1" style="font-size:1.5em;" >
                <ul class="nav navbar-nav">
                    <li>
                        <a href="#" target="blank"><i class="fa fa-twitter"></i></a>
                    </li>
                    <li>
                        <a href="#"><i class="fa fa-envelope"></i></a>
                    </li>
                    <li>
                        <a href="#" target="blank"><i class="fa fa-facebook"></i></a>
                    </li>
                    <li>
                        <a href="#" target="blank"><i class="fa fa-instagram"></i></a>
                    </li>
                </ul>
            </div>

        </div>

    </nav>

知道我错过了什么或做错了吗?

2 个答案:

答案 0 :(得分:3)

您忘了为导航栏指定样式。将<nav class="navbar" role="navigation">更改为<nav class="navbar navbar-default" role="navigation">。它将为您创建汉堡包菜单。然后,您必须设置导航栏的样式。

答案 1 :(得分:2)

https://jsfiddle.net/13p6um3w/

我在您的代码中发现了一些拼写错误(未公开的引号,标签)

<nav class="navbar" role="navigation">
    <div class="container">

        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <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="index.html" style="font-size:2.9em;">MY SITE</a>
        </div>

        <div class="collapse navbar-collapse pull-right" id="bs-example-navbar-collapse-1" style="font-size:1.5em; color: black;" >
            <ul class="nav navbar-nav">
                <li>
                    <a href="#" target="blank">l1<i class="fa fa-twitter"></i></a>
                </li>
                <li>
                    <a href="#">l2</a>
                </li>
                <li>
                    <a href="#" target="blank">l3<i class="fa fa-facebook"></i></a>
                </li>
                <li>
                    <a href="#" target="blank">l4<i class="fa fa-instagram"></i></a>
                </li>
            </ul>
        </div>
    </div>
</nav>