HeeHeeHaha
HeeHeeHaha

Reputation: 139

Bootstrap Button Toggle Does Not Open The LI

I have created this page using Bootstrap. When I drag the page to a narrower size the Navbar disappears and is replaced with a button. The idea of this button is that once clicked on it will open up the Nav options. This last bit does not happen and I can not seem to find a resolution. I have been scrolling the web for ages with no success. Please help.

<!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>Grid System 3</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.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>

      .box {
        border: 1px solid grey;
        background-color: #D3D3D3;
      }

    </style>

  </head>
  <body>

    <div class="navbar navbar-inverse">

      <div class="container">

        <div class="navbar-header">
          <a href="" class="navbar-brand">My Website</a>

          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">

          <span class="sr-only">Toggle navigation</span>

          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>

          </button>

        </div>

        <div class="collapse navbar-collapse">

          <ul class="nav navbar-nav">
            <li><a href="">Page 1</a></li>
            <li><a href="">Page 2</a></li>
            <li><a href="">Page 3</a></li>
          </ul>

        </div>

      </div>

    </div>

    <h1>Hello, world!</h1>

    <div class="container">

      <div class="row">
        <div class="col-md-4 box">.col-md-4</div>
        <div class="col-md-4 box">.col-md-4</div>
        <div class="col-md-4 box">.col-md-4</div>
      </div>


    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>

  </body>
</html>

Upvotes: 1

Views: 108

Answers (1)

gavgrif
gavgrif

Reputation: 15499

The most obvious thing to look for is that you have a folder called js with the bootstrap min js within it and called bootstrap.min.js and because you are calling the jQuery from a CDN, you will need to have an active connection to the net and not be working solely from a local server.

You also need to put an id on the navbar collapse and have that as the target for the button because there are more than 1 items in the page with the class of "navbar".

As follows:

<!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>Grid System 3</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.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>

      .box {
        border: 1px solid grey;
        background-color: #D3D3D3;
      }

    </style>

  </head>
  <body>

    <div class="navbar navbar-inverse">

      <div class="container">

        <div class="navbar-header">
          <a href="" class="navbar-brand">My Website</a>

          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">

          <span class="sr-only">Toggle navigation</span>

          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>

          </button>

        </div>
        <div id="navbar" class="navbar-collapse collapse">  


          <ul class="nav navbar-nav">
            <li><a href="">Page 1</a></li>
            <li><a href="">Page 2</a></li>
            <li><a href="">Page 3</a></li>
          </ul>

        </div>

      </div>

    </div>

    <h1>Hello, world!</h1>

    <div class="container">

      <div class="row">
        <div class="col-md-4 box">.col-md-4</div>
        <div class="col-md-4 box">.col-md-4</div>
        <div class="col-md-4 box">.col-md-4</div>
      </div>


    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>


  </body>
</html>

I have tested it and it works as expected.

Upvotes: 2

Related Questions