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/
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>
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>
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