Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap navbar toggle not working

Using the code below I am attempting to create a responsive web layout, that on reduction of the screen size, a navbar toggle button will display, and on select will list the page navigation. I am successful that the toggle button displays, however on click, nothing happens. I have reviewed various of Bootstrap examples and cannot pin point why mine is failing. Any assistance would be appreciated.

 <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        <span class="icon-bar"></span>
          </button>

     <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="../navbar/">Default</a></li>
            <li><a href="../navbar-static-top/">Static top</a></li>
            <li class="active"><a href="./">Fixed top <span class="sr-only">(current)</span></a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>  
like image 504
user289040 Avatar asked May 10 '15 14:05

user289040


People also ask

Why is my navbar not collapsing?

For navbars that never collapse, add the . navbar-expand class on the navbar. For navbars that always collapse, don't add any . navbar-expand class.

What does navbar expand LG do?

navbar-expand-xl|lg|md|sm (stacks the navbar vertically on extra large, large, medium or small screens). To add links inside the navbar, use a <ul> element with class="navbar-nav" .


1 Answers

You are probably not including the necessary resources (javascript files).

try adding these lines to your code

in your head section of the html page add:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css
">

Before you close the body tag add this:

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
like image 107
Cisum Inas Avatar answered Oct 01 '22 23:10

Cisum Inas