we are developing an application and we are using twiiter bootstrap 3 we have created a navigation bar with nav-pills
<ul class="nav nav-pills head-menu"> <input type="hidden" id="selected_menu_item" value="=$selectedMenuId; ?>" /> <li> <a href="#" id="welcome"> Welcome text ... </a> </li> <li><a href="#" id="kitchen">Kitchen</a></li> <li><a href="#" id="programma" > Programma</a></li> <li><a href="#" id="foodart" >foodart text</a></li> </ul>
can anyone with bootstrap experience help us, if we can make this nav-pills collapsible and responsive when size is reduced just as we can do easily with nav-bars?
thanks in advance
To create a collapsible navigation bar, use a button with class="navbar-toggler", data-toggle="collapse" and data-target="#thetarget" . Then wrap the navbar content (links, etc) inside a div element with class="collapse navbar-collapse" , followed by an id that matches the data-target of the button: "thetarget".
To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a . tab-pane class with a unique ID for every tab and wrap them inside a <div> element with class . tab-content .
The navbar-collapse refers to the menu that is in the mobile view with the navbar (contains links, and toggle-friendly content). They are in the bootstrap CSS (see here). See this for a full rundown of how the navbar and collapse work together. Follow this answer to receive notifications.
First, you need to include HTML for the menu button once your menu collapses.
<div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div>
Then, you need to wrap your nav-pills
in a div containing Bootstrap's collapse class.
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav nav-pills head-menu"> <input type="hidden" id="selected_menu_item" value="=$selectedMenuId; ?>" /> <li><a href="#" id="welcome">Welcome text ...</a></li> <li><a href="#" id="kitchen">Kitchen</a></li> <li><a href="#" id="programma" > Programma</a></li> <li><a href="#" id="foodart" >foodart text</a></li> </ul> </div>
You can then wrap all of this in a fluid-container and Bootstrap's navbar navbar-default
with role=navigation
.
Additionally, you could add a bit of jQuery to handle "stacking" your menu when it is collapsed instead of remaining horizontal. To do this, Bootstrap's events for show/hide collapse will do the trick: show.bs.collapse
and hide.bs.collapse
.
//Stack menu when collapsed $('#bs-example-navbar-collapse-1').on('show.bs.collapse', function() { $('.nav-pills').addClass('nav-stacked'); }); //Unstack menu when not collapsed $('#bs-example-navbar-collapse-1').on('hide.bs.collapse', function() { $('.nav-pills').removeClass('nav-stacked'); });
Working Demo Here
Another method to try is to set navbar li
to 100%
:
@media (max-width: 768px) { #navbar li { width:100%; } }
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