When I shrink the window and click the button it doesn't respond. How do I fix this?
<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 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>
Libraries are jQuery 2.1.3 and bootstrap 3.3.1.
In Bootstrap 5 data attributes are now namespaced in the js plugin with "bs", so for example data-toggle will not work anymore and you will need to use data-bs-toggle instead.
Add data-toggle="buttons" to a . btn-group containing those modified buttons to enable their toggling behavior via JavaScript and add . btn-group-toggle to style the <input> s within your buttons. Note that you can create single input-powered buttons or groups of them.
The data-toggler= “collapse” is used with navbar-toggler for the working button. This button helps to hide and show the items of the navbar. collapse navbar-collapse class is placed in the main div tag. This class is used for control and cover all the content Navbar with collapsing.
Demo: http://jsfiddle.net/u1s62Lj8/1/
You need the jQuery and Boostrap Javascript files included in your HTML page for the toggle to work. (Make sure you include jQuery before Bootstrap.)
<html> <head> // stylesheets here <link rel="stylesheet" href=""/> </head> <body> //your html code here // js scripts here // note jquery tag has to go before boostrap <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> </body> </html>
Your code looks great, the only thing i see is that you did not include the collapsed class in your button selector. http://www.bootply.com/cpHugxg2f8 Note: Requires JavaScript plugin If JavaScript is disabled and the viewport is narrow enough that the navbar collapses, it will be impossible to expand the navbar and view the content within the .navbar-collapse.
The responsive navbar requires the collapse plugin to be included in your version of Bootstrap.
<div class="navbar-wrapper"> <div class="container"> <nav class="navbar navbar-inverse navbar-static-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> </button> <a class="navbar-brand" href="#">Project name</a> </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> </nav> </div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With