问题
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>
回答1:
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:

来源:https://stackoverflow.com/questions/23875090/changing-menu-order-on-collapsed-navbar-in-bootstrap-3