简体   繁体   中英

Bootstrap 3: navbar collapse collapsing but not expanding

I am building a fairly simple static website with Bootstrap 3.

In terms of navigation, I need a full-width navbar on desktop and a "hamburger" menu on mobile.

So I went with Bootstrap's navbar-collapse:

<nav class="navbar navbar-default">
  <div class="container">
    <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="index.html"><img src="images/logo.png" alt="" /></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 navbar-right press">
              <li><a href="about.html">About</a></li>
              <li><a href="faq.html">FAQ</a></li>
              <li><a href="http://www.domain.com/blog/">Blog</a></li>
              <li><a href="index-FR.html"><img src="images/FR-flag-icon.png" alt="French Version" /></a></li>
              <li><a href="index.html"><img src="images/US-flag-icon.png" alt="English Version" /></a></li>
          </ul>
      </div>
    </div>
</nav>

As suggested in many other similar questions, like this one or that one , I DID check that I had the latest Bootstrap JS file included, with the following line between my <head></head> tags:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

—————

UPDATE : I also have the following inludes in my <head></head> :

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all">
        <!-- web-font -->
        <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,100,200,300,500,600,' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/animate.css">
        <link rel="stylesheet" href="css/jquery.wordrotator.css">       
        <!-- web-font -->
        <!-- js -->
        <script src="js/jquery.min.js"></script>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="keywords" content="email, productivity app, iphone app, clarity, peace" />

In addition, below the above code, I also have some custom JS scripts.

—————

UPDATE 2 : here are my browser console logs:

http://localhost:8888/timyo/js/move-top.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8888/timyo/js/easing.js Failed to load resource: the server responded with a status of 404 (Not Found)
bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher
http://localhost:8888/timyo/images/themes.png Failed to load resource: the server responded with a status of 404 (Not Found)
base.js:1624 SVG's SMIL animations (<animate>, <set>, etc.) are deprecated and will be removed. Please use CSS animations or Web animations instead.

—————

However, when I am in my browser, and I resize the window, the navbar will turn into the hamburger menu, but the hamburger menu is not clickable and does not expand.

Any idea what is wrong here?

The error was:

bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher

I simply updated my section with:

<script src="http://code.jquery.com/jquery-2.1.4.js"></script>

and now it works perfectly.

You need to also load the Bootstrap CSS theme, minified or full:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

Reference the Getting Started here: http://getbootstrap.com/getting-started/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM