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
Complete Solution
See it in CodePan
@Tricky12 has a good solution, i used for myself, just changed the last part.
The part: hidden.bs.collapse trigger when the menu is fully closed, while hide.bs.collapse trigger when it starting to close.
if you trigger the
.removeClass('nav-stacked');
before collapsed menu it fully closed, will show the horizontal menu for a fraction of a second before is fully closed.Hope this will help someone.
I've tried to wrap
navbar-pills
intonavbar-collapse
but it was looking awful, because it has different indents. So I made two different navbars using classesvisible-xs
(for navbar-collapse) andhidden-xs
(for nav-pills).The .nav-justified class of bootstrap will take care of everything. This will resize the links in browsers wider than 768px. Smaller than that, the links will be stacked. Simply add it to the element and you are good to go.
Doesn't address the question how to collapse the items, I am stating how to stack them. So my answer might not help, but I think it contributes, hopefully.
First, you need to include HTML for the menu button once your menu collapses.
Then, you need to wrap your
nav-pills
in a div containing Bootstrap's collapse class.You can then wrap all of this in a fluid-container and Bootstrap's
navbar navbar-default
withrole=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
andhide.bs.collapse
.Working Demo Here
Another method to try is to set
navbar li
to100%
: