Im trying to write a navbar in Bootstrap 3, there is a navbar and some brand and other stuff including a search form in it
I want the search form to fill the extra space in navbar, what should i do?
<div class="navbar navbar-fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Brand</a>
<form class="navbar-form pull-left">
<input type="search" class="form-control search-box">
<button type="submit" class="btn btn-default glyphicon glyphicon-search"></button>
</form>
<div class="navbar-form btn-group pull-right">
<button type="button" class="btn btn-default">User</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>My Account</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Logout</li>
</ul>
</div>
</div>
</div>
A lot has changed with Bootstrap 3. You need to specify widths for inputs. You can try something like...
<div class="navbar navbar-fixed-top">
<div class="container">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-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 class="nav-collapse collapse">
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
User <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form">
<button type="submit" class="btn btn-default glyphicon glyphicon-search"></button>
<input type="search" class="form-control pull-left" style="width:70%;">
</form>
</div><!--/.nav-collapse -->
</div>
</div>
Demo on Bootply: http://bootply.com/70142
Because your menu is fixed to the top, you can use something like this:
<form class="navbar-form navbar-left"
style="display:inline;
position:absolute;
margin-right: 140px;">
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Search</button>
</span>
</div>
</form>
The display:inline is used that the absolute position is directly next to your left navbar-brand or maybe a nav navbar-nav. The class form-control of bootstrap will use it's 100% width to fill the rest of the navbar with the input field. Because you have got a dropdown on the right side of form define a matching margin to the right, so the element does not overlap.
Example: on plunker
It works with IE and Chrome but unfortunately not on Firefox and Safari. Ideas how to fix this are welcome.
Try this
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li><a class="brand" href="#">Brand</a></li>
<li>Nav 2</li>
<li>Nav 3</li>
</ul>
<form class="navbar-search pull-left">
<input type="text" class="search-query" placeholder="Search">
</form>
<ul class="nav pull-right">
<li class="dropdown">
User <b class="caret"></b>
<ul class="dropdown-menu">
<li>My Account</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Logout</li>
</ul>
</li>
</ul>
</div>
</div>
Related
I'm new to front end design and am having challenges implementing a search box with filters into my navbar. I know this is potentially trivial but I have found it very challenging, and typically end up with a jumbled mess when I insert the searchbox code into my desired area (commented in the second code block).
The code for the search box is:
<div class="container">
<div class="row">
<div class="col-xs-4 col-xs-offset-2">
<div class="input-group">
<div class="input-group-btn search-panel">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span id="search_concept">Filter by</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>Contains</li>
<li>It's equal</li>
<li>Greather than ></li>
<li>Less than < </li>
<li class="divider"></li>
<li>Anything</li>
</ul>
</div>
<input type="hidden" name="search_param" value="all" id="search_param">
<input type="text" class="form-control" name="x" placeholder="Search term...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</div>
</div>
The code for my nav bar is as follows, with a comment indicating where I need the search box to go:
<nav class="navbar navbar-default">
<div class="container-fluid">
<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="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="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About</li>
<li>
<!--SEARCH BAR HERE -->
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Log in</li>
<li>Join us</li>
<li><i class="fa fa-twitter color-twitter"></i></li>
<li><i class="fa fa-facebook color-facebook"></i></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
The final result should look something like:
NavBar Desired Result
Sincere gratitude in advance.
Here is a working snippet based on Bootstrap 3 (click to "Expand snippet"):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<!--div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button-->
<div class="input-group">
<div class="input-group-btn search-panel">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span id="search_concept">Filter by</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>Contains</li>
<li>It's equal</li>
<li>Greather than ></li>
<li>Less than < </li>
<li class="divider"></li>
<li>Anything</li>
</ul>
</div>
<input type="hidden" name="search_param" value="all" id="search_param">
<input type="text" class="form-control" name="x" placeholder="Search term...">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span></button>
</span>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
This Link here <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
And also the relative CodePen: https://codepen.io/beaver71/pen/pdmBMr
I have a Bootstrap3 navbar with a dropdown menu.
I want my "logout" form inside that dropdown. It is not a visible form, just a logout button within a form.
I tried this:
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
Dropdown<span class="caret"></span>
<ul class="dropdown-menu">
<!-- this dropdown menu item looks right -->
<li>Foo</li>
<!-- this dropdown menu item (a logout form) does not -->
<li><form action="/logout" method="post"><button type="submit" class="btn btn-link navbar-btn navbar-link">Log off</button></form></li>
</ul>
</li>
</ul>
</div>
But it is not styled properly.
How do I make it match normal dropdown links? I hope I don't need to manually tweak the css, and that there's a built in way to do this?
That will not really work, but you can create the logout-form somewhere else:
<form id="logout-form" style="display:none" action="/logout" method="POST"></form>
and when the user clicks on logout you just call
document.getElementById("logout-form").submit();
in Javascript or you set
onclick="document.getElementById('logout-form').submit();"
try this Sample [UPDATED]
.btn-logout {
width: 100%;
padding: 3px 20px !important;
text-align: left !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
<li role="separator" class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
<li>
<form>
<button type="submit" class="btn btn-link btn-logout">Logout</button>
</form>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
</div>
</div>
</div>
I have helped you in some way
try this just give link to .java/servlet file.
<li><span class="glyphicon glyphicon-user"></span>Logout</li>
I want do a nav like this:
Logo::::::::|:::::Dropdown+Search(center):::::|::::::::::Glyphcon1Glyphcon2|
In this moment I make this, but the glyphcon show it down of nav content.
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target=".navbar-ex1-collapse">
<span class="sr-only">Desplegar navegaciĆ³n</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logotipo</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<div class="input-group navbar-form navbar-center">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div><!-- /btn-group -->
<input type="text" class="form-control" aria-label="...">
</div><!-- /input-group -->
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span></li>
<li><span class="glyphicon glyphicon-shopping-cart"></span></li>
</ul>
</div>
</nav>
How can I put the dropdown+search in the center of the nav and put the glyphcon in the same line without problems?
<div class="input-group navbar-form navbar-center"> occupying the whole line so next <div class="nav navbar-right navbar-nav"> goes to right of next line. to fix that put <div class="input-group navbar-form navbar-center"> inside other <div class="nav navbar-nav navbar-left">
In element nav navbar-nav navbar-right you are including two icons in <li></li> tag which is similar like text and it goes down but when you include icon inside tag a/c to bootstrap <a> tag it is padded inside nav class.
<div class="collapse navbar-collapse navbar-ex1-collapse">
<div class="nav navbar-nav navbar-left">
<div class="input-group navbar-form navbar-center">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div><!-- /btn-group -->
<input type="text" class="form-control" aria-label="...">
</div><!-- /input-group -->
</div>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span></li>
<li><span class="glyphicon glyphicon-shopping-cart"></span></li>
</ul>
</div>
I am trying to achieve a two row navigation using BS 3, but I am having a hard time find out how to do it. Every method I've tried has failed. I would like to keep the markup as standard as possible. Here's what I want it to look like:
http://jsfiddle.net/technotarek/ePGa9/
The example uses old BS code. I can't seem to get it to work in BS 3.0.
Here's my attempt. The logo is quite large, but I want it to scale accordingly.
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-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 class="navbar-brand" href="/"><img class="img-responsive" src="http://placehold.it/490x164&text=Logo" alt="My Logo"></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<form class="navbar-form pull-right">
<div class="input-group">
<input type="text" class="search-box-text form-control" />
<span class="input-group-btn">
<button type="submit" class="btn btn-default"><i class="icon-search"></i></button>
</span>
</div>
</form>
<ul class="nav navbar-nav pull-right">
<li>Register</li>
<li>Log in</li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</nav>
Your code is here BootstrapNavbarWithLogoSearchbarResponsive
html
<div class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"> <img src="http://placehold.it/70x70">
</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav">
<li class="active">Active</li>
<li>Link</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Dropdown header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<input type="text" class="form-control col-lg-8" placeholder="Search">
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
</div>
css
.navbar-brand {
float: left;
height: 10%;
padding: 0;
}
I just need to know where to change it to align everything including the brand to the left. I can't for the life of me find it anymore in the CSS. I want to make the navbar skinnier and everything align from the far left, and not in the center of the webpage. :/
<div class="navbar navbar-inverse navbar-left 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="#"><img src="something.png" /></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>link</li>
<li>link</li>
<li class="dropdown">
Forums <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right">
<div class="form-group">
<input type="text" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control">
</div>
<button type="submit" class="btn btn-success">Sign in</button>
</form>
</div><!--/.navbar-collapse -->
</div>
</div>
There is this helper class class="pull-left" that could possibly help you.
I've missed it the first times, bootstrap navbar-component-alignment.
However, if you want to align a dropdown menu item in the navbar, you should use 'dropdown-menu-left' in place of the 'dropdown-menu' class bootstrap dropdown-alignment.