I have a Bootstrap 3 Navbar that has two right-justified <ul>
sections which gives me this:
When the menu is collapse for mobile, I get this:
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>
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.
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.
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.
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:
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