Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 - item float right in navigation

This is my current navigation:

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">ApplicationName</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav" id="main-navigation">
                <li><a href="#">Item1</a></li>
                <li><a href="#">Item2</a></li>
            </ul>
        </div>
    </div>
</nav>

With this navigation I'm having this: enter image description here

What I actually want is this: enter image description here

I've tried floating of the anchor tag but it's floating just inside the li tag. In ExtJS I'm having the '->' item which provides me this behavior. How can I do this?

I'm using Bootstrap 3.1.1.

Thank you. :)

like image 228
NullCod3 Avatar asked Feb 27 '14 22:02

NullCod3


2 Answers

Add the pull-right class to the ul tag

Full Example:

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">ApplicationName</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav" id="main-navigation">
                <li><a href="#">Item1</a></li>
            </ul>
            <ul class="nav navbar-nav pull-right" id="main-navigation">
                <li><a href="#" class="pull-right">Item2</a></li>
            </ul>
        </div>
    </div>
</nav>

Result: works!

like image 93
Curtis W Avatar answered Oct 12 '22 12:10

Curtis W


You have to give the element this:

CSS

li.right {
    position: absolute;
    right: 0;
}

HTML

<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">ApplicationName</a>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav" id="main-navigation">
            <li><a href="#">Item1</a></li>
            <li class="right"><a href="#">Item2</a></li>
        </ul>
    </div>
</div>

Working Example

like image 36
Sebsemillia Avatar answered Oct 12 '22 13:10

Sebsemillia