无法使用bootstrap 3.3.7创建汉堡包

时间:2017-09-01 14:49:52

标签: html css twitter-bootstrap-3

我正在尝试制作一个导航栏,当屏幕很小时会成为一个汉堡包....但只是无法弄明白为什么它不起作用......我把所有内容放在折叠标签中但仍然没有工作。谢谢你的时间!!

   <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>Prof Yuh-Jong Hu</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <link rel="stylesheet" href="DadWebPage.css">
        <!-- Fonts: Roboto Condensed -->
        <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
      </head>

      <body>
        <!-- nav-bar -->
        <nav class="navbar navbar-inverse navbar-fixed-top">
          <div class="container">

            <!-- navbar header -->
            <div class="navbar-header">
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-expanded="false">
                <!-- the hamburger -->
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>

              <p id="brandName" class="navbar-text">Matthew</p>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="myNavbar">
              <ul class="nav navbar-nav">

                <li class="active"><a href="DadWebPageMain.html">Home</a></li>
                <li><a href="Career.html">Career</a></li>
                <li><a href="Projects.html">Projects</a></li>
                <li><a href="Publications.html">Publications</a></li>
                <li><a href="AcademicServices.html">Academic Services</a></li>
                <li><a href="Talks.html">Talks</a></li>
                <li><a href="GraduateStudentsAdvising.html">Graduate Students Advising</a></li>

              </ul>
            </div>
          </div>
        </nav>
        <script src="DadWebPage.js"></script>
      </body>
    </html>

2 个答案:

答案 0 :(得分:0)

您必须插入Bootstrap的Javascript以及jQuery库才能使NavBar正常运行!将其添加到最后的body标记内。

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

尽管如此,所有信息都可以在他们documentation中找到,解释navbar元素所需的内容。

您可能需要提出的问题:

  1. 您是否在网页中加入了CSS和Javascript?
  2. 是否有任何控制台日志指示错误
  3. 确保您拥有viewport的元标记。因为它用于确定您网页的大小:<meta name="viewport" content="width=device-width, initial-scale=1">
  4. 您的网页上是否启用了JS?
  5. 您的网页应该看起来像Bootstrap的101模板 - 也可以在他们的文档中找到:

    <!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">
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <title>Bootstrap 101 Template</title>
    
        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet">
    
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    
    <body>
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- 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="#bs-example-navbar-collapse-1" 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="#">Brand</a>
                </div>
    
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                        <li><a href="#">Link</a></li>
                        <!-- etc... -->
                    </ul>
                </div>
                <!-- /.navbar-collapse -->
            </div>
            <!-- /.container-fluid -->
        </nav>
    
        <h1>Hello, world!</h1>
    
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="js/bootstrap.min.js"></script>
    </body>
    
    </html>
    

答案 1 :(得分:0)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>Prof Yuh-Jong Hu</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <!-- Fonts: Roboto Condensed -->
        <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
      </head>

      <body>
        <!-- nav-bar -->
        <nav class="navbar navbar-inverse navbar-fixed-top">
          <div class="container">

            <!-- navbar header -->
            <div class="navbar-header">
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-expanded="false">
                <!-- the hamburger -->
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>

              <p id="brandName" class="navbar-text">Matthew</p>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="myNavbar">
              <ul class="nav navbar-nav">

                <li class="active"><a href="DadWebPageMain.html">Home</a></li>
                <li><a href="Career.html">Career</a></li>
                <li><a href="Projects.html">Projects</a></li>
                <li><a href="Publications.html">Publications</a></li>
                <li><a href="AcademicServices.html">Academic Services</a></li>
                <li><a href="Talks.html">Talks</a></li>
                <li><a href="GraduateStudentsAdvising.html">Graduate Students Advising</a></li>

              </ul>
            </div>
          </div>
        </nav>
      </body>
    </html>

您必须为崩溃类工作添加jQuery。