Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Menu Order on Collapsed Navbar in Bootstrap 3

I have a Bootstrap 3 Navbar that has two right-justified <ul> sections which gives me this:

enter image description here

When the menu is collapse for mobile, I get this:

enter image description here

I have two questions related to the collapsed menu. 1) How can I get the buttons to appear at the bottom of the collapsed menu instead of the top? 2) How can I change the styling of the buttons in the collapsed menu (without affecting the style in the horizontal menu)?

Below is the markup for this Navbar. And yes I have a reason for having two separate <ul> sections:

<div class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a href="#" class="navbar-brand">My Site</a>
            </div>
            <div class="collapse navbar-collapse navHeaderCollapse">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#" class="btn navbar-btn" id="Btn_1">Button One</a></li>
                    <li><a href="#" class="btn navbar-btn" id="Btn_2">Button Two</a></li>                    
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">Item1</a></li>
                    <li><a href="#">Item2</a></li>                    
                    <li><a href="#">Item3</a></li>
                    <li><a href="#">Item4</a></li>
                </ul>                
            </div>            
        </div>
    </div>
like image 399
Tom Patrick Avatar asked May 26 '14 17:05

Tom Patrick


People also ask

How do I move my menu to the right in bootstrap?

ml-auto class in Bootstrap can be used to align navbar items to the right. The . ml-auto class automatically aligns elements to the right.

How do I move the navbar brand to the left?

To align the navbar logo to the left of the screen with the Bootstrap method is a quick trick that can save you from writing extra CSS. In this, we simply add another div tag above the div tag having class navbar navbar-expand-lg navbar-light bg-light fixed-top py-lg-0.

How do I move nav bar content to the right?

Using flex alignment class The navbar items can be aligned using flex utility. Use . justify-content-end class on collapse menu to justify items to the right.


1 Answers

I ended up finding a simpler solution for the reformatting and reordering of the button links on the collapsed navbar, one that doesn't require new javascript code:

        <div class="collapse navbar-collapse navHeaderCollapse">
            <ul class="nav navbar-nav navbar-right hidden-xs">
                <li><a href="#" class="btn navbar-btn" id="Btn_1">Button One</a></li>
                <li><a href="#" class="btn navbar-btn" id="Btn_2">Button Two</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">Item1</a></li>
                <li><a href="#">Item2</a></li>
                <li><a href="#">Item3</a></li>
                <li><a href="#">Item4</a></li>
            </ul>
            <ul class="nav navbar-nav visible-xs">
                <li><a href="#" >Button One</a></li>
                <li><a href="#" >Button Two</a></li>
            </ul>
        </div>

I simply duplicated the Button One and Button Two <ul> section and added it to the bottom. I then removed the classes and ID on the <a> links so that no button formatting would occur. Finally, I added the hidden-xs bootstrap class to the top <ul> and visible-xs to the bottom <ul> class. That did the trick:

enter image description here

like image 108
Tom Patrick Avatar answered Oct 31 '22 06:10

Tom Patrick