Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is left-aligning the button of a Twitter Bootstrap navbar possible?

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?

like image 628
balteo Avatar asked Apr 19 '15 15:04

balteo


People also ask

How do I move a button from right to left in Bootstrap?

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.

How do I make Bootstrap navbar left to right?

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.

How do I align The navbar in Bootstrap 4?

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.

Why are my buttons not align with other buttons in Bootstrap?

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.

What is navbar in Twitter Bootstrap?

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.

How do I right align the navigation bar in HTML?

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:


2 Answers

<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

like image 78
isherwood Avatar answered Sep 19 '22 15:09

isherwood


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>
like image 36
AV2000 Avatar answered Sep 18 '22 15:09

AV2000