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
Related
I have created a navbar but when I try to resize the screen, at one point search bars comes below rather than collapsing. MY code is :
//row start
<div class="row">
//navbar class with affix used in css
<nav class="navbar navbar-default" data-spy="affix" data-offset-top="150">
<div class="container-fluid">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Home</a>
</div>
<div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li>Technology</li>
<li>Sports</li>
<li>Science</li>
<li>Entertainment</li>
<li>Science</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">More <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Life</li>
<li>Tours and Travels</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<form style="float:right" class="navbar-form" role="search" aria-expanded="false">
<div class="input-group add-on">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
</div>
I see the 'More' dropdown you have there as a layout compromise and I just feel that more compromise is needed. I've condensed all menu links in a dropdown, on small screens.
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Home</a>
</div>
<div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav visible-sm">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Technology</li>
<li>Sports</li>
<li>Science</li>
<li>Entertainment</li>
<li>Science</li>
<li>Life</li>
<li>Tours and Travels</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav visible-md visible-lg">
<li>Technology</li>
<li>Sports</li>
<li>Science</li>
<li>Entertainment</li>
<li>Science</li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">More <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Life</li>
<li>Tours and Travels</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><form style="float:right" class="navbar-form" role="search" aria-expanded="false">
<div class="input-group add-on">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
I would like to add a menu button (3 horizontal lines) to the right of my Layout form , so that it will be not responsive (visible at the normal resolution 100% of my PC browser 1366 x 768 without zoomig or unzooming), but I don't know how with the Bootstrap United theme.
Thank you in advance for your answers.
Here is my HTML page :
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title - BEMF Revues</title>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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>
#Html.ActionLink("BEMF Revues", "Index", "Home", new { area = "" }, new { #class = "navbar-brand" })
</div>
<div id="navbarCollapse" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown active">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Revues<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Support de demande</li>
<li>Support de revue</li>
<li>Tableau de suivi</li>
<li class="divider"></li>
<li>Support de contacts</li>
<li>Ticket OTRS</li>
</ul>
</li>
<li>#Html.ActionLink("À propos", "About", "Home")</li>
<li>#Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
<form class="navbar-form navbar-left">
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right"><li>Messages <span class="badge">0</span></li></ul>
<ul class="nav navbar-text navbar-right">Bonjour, #Environment.UserName</ul>
</div>
</div>
</div>
<div class="container body-content">
#RenderBody()
<hr />
<footer>
<p>© #DateTime.Now.Year - BEMF Revues</p>
</footer>
</div>
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required: false)
</body>
</html>
You can always create a right-aligned (navbar-right) drop-down (dropdown, dropdown-toggle, dropdown-menu) menu with a hamburger glyph (glyphicon-menu-hamburger) in it.
<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="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link</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>Separated link</li>
<li 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>
</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>
</nav>
JS Fiddle
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 would like to use navbar-right on a navbar-form and a navbar-nav however it ends up putting the form on one row and the navbar_nav on another row on the right. How can I get the navbar to show the brand on the left and on the right is a search field followed by a nav links.
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid col-sm-12 col-lg-offset-2 col-lg-8">
<!-- 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="/" style="white-space:nowrap">Site</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar_collapse">
<div class="navbar-right">
<form class="navbar-form" role="search" ng-submit="collectionSearch()">
<div class="form-group">
<input type="text" class="form-control" placeholder="Collection ID"
ng-model="cSearch" size=10 required>
</div>
</form>
<ul class="nav navbar-nav">
<li id="create_tab">Create</li>
<li id="tests_tab">Tests</li>
<li id="collections_tab">Collections</li>
<li id="account_tab">Account</li>
<li id="logout_tab" >Logout</li>
</ul>
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Any suggestions are appreciated. Thank you!
You need to use this bootstrap classes navbar-form and navbar-left to move the search icon on left side. Here is a DEMO.
<form class="navbar-form navbar-left" role="search" ng-submit="collectionSearch()">
</form>
If I understand correctly, this should answer your question:
http://jsfiddle.net/zu5uoopc/
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<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="#">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</li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div><!-- /.navbar-collapse -->
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;
}