PixelPaul
PixelPaul

Reputation: 2801

Two lists in navbar using 'navbar-right', displays second list first?

In Bootstrap 3 I'm trying to create a navbar which will have to ul, both of which will align to the right. But when I add navbar-right to both ul's, they both align to the right, but the second ul in the markup displays first? What do I need to do to get them to display in the proper sequence?

    <div class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <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>
      <a class="navbar-brand" href="#">Brand</a>
    </div>
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav navbar-right">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#about">Register</a></li>
        <li><a href="#contact">Login</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

Link to Codeply: https://www.codeply.com/go/LibLIdo8NW

Upvotes: 1

Views: 681

Answers (3)

Amit Kumar Singh
Amit Kumar Singh

Reputation: 4475

Take navbar-right class to container for both UL's.

<div class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <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>
          <a class="navbar-brand" href="#">Brand</a>
        </div>
        <div class="collapse navbar-collapse navbar-right">
          <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>
          <ul class="nav navbar-nav ">
            <li><a href="#about">Register</a></li>
            <li><a href="#contact">Login</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <div class="container">
      <div class="text-center">
        <h1>Bootstrap starter template</h1>
        <p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
      </div>
    </div>

Upvotes: 0

Hodaut96
Hodaut96

Reputation: 93

This is the right process. Check this link. In order to have your desired result you just have to switch the ul's for these elements.

Upvotes: 0

Saurabh
Saurabh

Reputation: 2775

Just write the ul for Register and Login first that will solve your issue.

<div class="collapse navbar-collapse">
    <ul class="nav navbar-nav navbar-right">
        <li><a href="#about">Register</a></li>
        <li><a href="#contact">Login</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div>

Updated link to your demo

Update:

The class navbar-right has the property float: right!important; which pushes the first element to the right most of the screen. Overriding this property would be another hack :)

Upvotes: 2

Related Questions