Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3: keep navbar items outside the collapse without wrapping to a new line? [duplicate]

I could use some help getting my Bootstrap 3 navbar to look right when collapsed.

Apologies if this is a duplicate question but a good long search hasn't yielded the answers I need.

I've created a responsive navbar based on the Bootstrap demo code. In it, there's a 40x40 image and a globe glyph that link to dropdown menus, which I've right-aligned and omitted from the nav Collapse.

Unfortunately, the 40x40 and globe glyph appear on a new line when the nav collapses, which I don't want.

My perfect layout when the nav collapses would be for the 40x40 and globe to appear on the same line as my brand image, the collapse button etc; right aligned, and not contained in the collapse.

Thank you for any advice you can give!

Code is like so:

    <nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-hd-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a href="index.php"><img class="navbar-brand img-responsive" src="http://placehold.it/138x38" alt="Logo"></a>
    </div>
     <div class="navbar-right">
        <ul class="nav"  style="float: right; display: inline-block !important">
            <li class="dropdown pull-right">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="http://placehold.it/40x40" alt="Profile Image" style="display: inline-block !important"/><b class="caret grey"></b></a>
                <ul class="dropdown-menu">
                    <li class="dropdown-header">Hello</li>
                    <li class="divider"></li>
                    <li><a href="">Thing 1</a></li>
                    <li class="divider"></li>
                    <li><a href="">Thing 2</a></li>
                </ul>
            </li>
        </ul>
        <ul class="nav"   style="float: right; display: inline-block !important">
            <li class="dropdown pull-right">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-globe grey"></span><b class="caret grey"></b></a>
                <ul class="dropdown-menu">
                    <li style="padding: 10px"><p>News</p></li>
                </ul>
            </li>
        </ul>

         <div class="collapse navbar-collapse navbar-hd-collapse">
             <ul class="nav navbar-nav">
                 <li class="active"><a href="">Product</a></li>
                 <li><a href="">Other Product</a></li>
                 <li><a href="">Third Product</a></li>
             </ul>
         </div>
    </nav>

JS Fiddle is here: http://jsfiddle.net/CaraGee/q8br8/

like image 527
CeeGee Avatar asked Sep 12 '13 10:09

CeeGee


2 Answers

Add Style=" float:right"; in the 40*40 and globe div... so that the 40x40 and globe glyph appear on a same line

 <div class="navbar-right" style="float:right;">
    <ul class="nav">
        <li class="dropdown pull-right">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="http://placehold.it/40x40" alt="Profile Image" style="display: inline-block !important"/><b class="caret grey"></b></a>
            <ul class="dropdown-menu">
                <li class="dropdown-header">Hello</li>
                <li class="divider"></li>
                <li><a href="">Thing 1</a></li>
                <li class="divider"></li>
                <li><a href="">Thing 2</a></li>
            </ul>
        </li>
    </ul>
    </div>
     <div class="navbar-right" style="float:right">
    <ul class="nav">
        <li class="dropdown pull-right">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-globe grey"></span><b class="caret grey"></b></a>
            <ul class="dropdown-menu">
                <li style="padding: 10px"><p>News</p></li>
            </ul>
        </li>
    </ul>
 </div>
like image 149
Bala Avatar answered Sep 29 '22 19:09

Bala


make a the collapse div with the align to the left: and the non collapsable elements inside a div with the align to the right like this:

<div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">Project name</a>
                <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>
            <!-- THIS WILL COLLAPSE-->
            <div class="navbar-collapse collapse navbar-left">
                <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>
            <!-- THIS WILL NOT COLLAPSE -->
            <div class="nav navbar-nav" >
                <form class="navbar-form navbar-right">
                    <div class="form-group">
                        <input type="text" placeholder="Usuario" class="form-control">
                    </div>
                    <div class="form-group">
                        <input type="password" placeholder="Contraseña" class="form-control">
                    </div>
                    <button type="submit" class="btn btn-success">Conectarse</button>
                </form>
            </div>
        </div>
    </div>
like image 21
Alejandro Silva Avatar answered Sep 29 '22 21:09

Alejandro Silva