I would like for the button to appear on the left-hand side of the menu on mobile devices. Is this possible with Twitter Bootstrap?
Here is my markup:
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
Bootply demo
To quote the official documentation:
Align nav links, forms, buttons, or text, using the .navbar-left or .navbar-right utility classes. Both classes will add a CSS float in the specified direction. For example, to align nav links, put them in a separate with the respective utility class applied.
These classes are mixin-ed versions of .pull-left and .pull-right, but they're scoped to media queries for easier handling of navbar components across device sizes.
I did try the pull-left
but I am worried as the official documentation mentions that navbar-left
is more appropriate - see above.
By the way navbar-left
does not work for me. Should I go ahead and use pull-left
despite what the documentation says?
Answer: Use the text-right Classtext-right on the containing element to right align your Bootstrap buttons within a block box or grid column. It will work in both Bootstrap 3 and 4 versions.
ml-auto class of Bootstrap 4 to align navbar items to the right. The . ml-auto class automatically gives a left margin and shifts navbar items to the right.
In Bootstrap 4, the Navbar is responsive by default and utilizes flexbox to make alignment of Navbar content much easier. It’s also a simple matter of using the new navbar-toggleable-* classes to change the Navbar breakpoint.
If you use the class .pull-right or .pull-left with buttons not in the same line, you are using the wrong classes of Bootstrap for the alignment of buttons. Because these classes may break your design and your buttons may overlap with other HTML elements.
Twitter Bootstrap provides Navbar component which is responsive in nature and can be used to serve as navigation menu for your web application or site. These navbars are collapsed and toggleable in mobile devices and stretch out horizontally for wider viewport.
Right-Aligned Navigation Bar. The .navbar-right class is used to right-align navigation bar buttons. In the following example we insert a "Sign Up" button and a "Login" button to the right in the navigation bar. We also add a glyphicon on each of the two new buttons:
<button type="button" class="pull-left navbar-toggle ...
Regarding your question edit, I'm not convinced that navbar-left
was intended to be used for the toggle button. It has explicit style statements that override what navbar-left
does.
If you do want to use it, however, it could be done by adding this to your custom stylesheet:
.navbar-toggle.navbar-left {
float: left;
margin-left: 10px;
}
Demo
You can use "pull-left" but you might have to add some left side padding to the icon bar using "padding-left" to the "navbar-header" div. Please see example below:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header" style="padding-left: 10px">
<button type="button" class="pull-left navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><asp:Literal ID="litMenuBar" runat="server"></asp:Literal></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> My Account</a></li>
</ul>
</div>
</div>
</nav>
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