Bootstrap 3 Navbar Collapse menu at Left for left and right navbar items
I have a Bootstrap 3 navbar with left nav items and right nav items (as shown below).
When collapsed, I want both the navbar-toggle (AKA the 'hamburger menu') and its items to be left aligned.
My code so far:
<nav class="navbar navbar-default custom-navbar" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Left</a></li>
<li><a href="#about">Left</a></li>
</ul>
<ul class="nav navbar-nav pull-right">
<li><a href="#about">Right</a></li>
<li><a href="#contact">Right</a></li>
</ul>
</div>
</nav>
The CSS to have the navbar-toggle on the left is:
@media (max-width:767px) {
.custom-navbar .navbar-right {
float: right;
padding-right: 15px;
}
.custom-navbar .nav.navbar-nav.navbar-right li {
float: left;
}
.custom-navbar .nav.navbar-nav.navbar-right li > a {
padding:8px 5px;
}
.custom-navbar .navbar-toggle {
float: left;
margin-right: 0
}
.custom-navbar .navbar-header {
float: left;
width: auto!important;
}
.custom-navbar .navbar-collapse {
clear: both;
float: none;
}
}
I have added a "pull-right" style to have the items aligned, with no success.
The "navbar-right" works badly. In fact, with it, I will have both right-hand items on the same row. Using "pull-right" they work as single rows, but still stay on the right.
This leaves me with:
The final result:
The code snippet is here.
I've made a few adjustments to your CSS and markup which you can view here.
One thing I'd point out is that pull-right
and the other pull
and push
classes are for rearranging grid columns.
You can use the !important
rule to override the default behaviour of pull-right.
@media (max-width:767px) {
.nav.navbar-nav.pull-right {
float: left !important;
}
}
Output in <768px devices:
Bootply
链接地址: http://www.djcxy.com/p/94562.html上一篇: 引导下拉菜单不会下拉