Bootstrap navbar search bar to the right - html

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>

Related

Adding a search box form to my navbar

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

How can i modify this bootstrap code?

I found a code from
http://usebootstrap.com/theme/facebook
But in this code, I want to make 'Home icon' never be collapsed at any browser size.
CODE:
<div class="navbar navbar-blue navbar-static-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
b
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
###▽▽▽ I want this icon remain on the navbar, not in collapsed dropdown menu
<i class="glyphicon glyphicon-home"></i>
###△△△ I want this icon remain on the navbar, not in collapsed dropdown menu
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
</div>
Bootply: https://www.bootply.com/lEfd188zDg
I tried to move <i class="glyphicon glyphicon-home"></i> to after b, but it looks very ugly.
I want that 'Home icon' is still seen in smaller browser size, being looks nicely not ugly. How can i modify well?
EDIT
Pic:
This simplified code is a little different from above code that i posted firstly.
Simplified code:
<div class="wrapper">
<div class="box">
<div class="row row-offcanvas row-offcanvas-left">
<div class="column col-sm-12 col-xs-12" id="main">
<!-- top nav -->
<div class="navbar navbar-blue navbar-static-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
<!-- /top nav -->
</div>
</div>
</div>
</div>
</div>
original result is like:
and in narrow browser,
But purpose result is like:
Would give me the way how to make this?
I just updated your HTML code and added CSS. Just replace it with yours. Please Only tap nav.
<style>
.heading-icons li{
padding: 9px 10px;
margin-top: 8px;
margin-right: 15px;
}
</style>
<div class="navbar navbar-blue navbar-static-top">
<div class="col-xs-6 col-sm-6">
<ul class="list-inline heading-icons">
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
</ul>
</div>
<div class="navbar-header col-xs-6 col-sm-6">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i
class="glyphicon glyphicon-user"></i></a>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
<!-- /top nav -->
</div>

Bootstrap 3 - How to get tab bar in navigation

How can I get a Bootstrap tabbar into the header top bar? (see screenshot)
This is my code at this moment:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<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="/">AppName</a>
</div>
<div class="navbar-collapse collapse">
<form method="post" id="logoutForm" class="navbar-right" action="/Account/LogOff">
<ul class="nav navbar-nav navbar-right" style="margin-right: 20px">
<li>
<a title="Manage" href="/Account/Claims">User</a>
</li>
<li>
<button type="submit" class="btn btn-link navbar-btn navbar-link">Log off</button>
</li>
</ul>
</form>
</div>
</div>
</div>
<ul class="nav nav-tabs">
<li>Home</li>
<li class="active">Link A</li>
<li class="">Link B</li>
<li class="">Link C</li>
<li class="">Link D</li>
<li class="">Admin</li>
</ul>
Thanks!
You have to move this code below inside of the navbar-header div after the navbar-brand tag.
<ul class="nav nav-tabs">
<li>Home</li>
<li class="active">Link A</li>
<li class="">Link B</li>
<li class="">Link C</li>
<li class="">Link D</li>
<li class="">Admin</li>
</ul>
Your code should look like this
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<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="/">AppName</a>
<ul class="nav nav-tabs">
<li>Home</li>
<li class="active">Link A</li>
<li class="">Link B</li>
<li class="">Link C</li>
<li class="">Link D</li>
<li class="">Admin</li>
</ul>
</div>
<div class="navbar-collapse collapse">
<form method="post" id="logoutForm" class="navbar-right" action="/Account/LogOff">
<ul class="nav navbar-nav navbar-right" style="margin-right: 20px">
<li>
<a title="Manage" href="/Account/Claims">User</a>
</li>
<li>
<button type="submit" class="btn btn-link navbar-btn navbar-link">Log off</button>
</li>
</ul>
</form>
</div>
</div>
</div>

How to make just one right justified nav element not to collapse on mobile devices?

I have a navbar with a bunch of navs. I want just the notifications dropdown to not be collapsed on xs devices. I also need the notifications to be in the specific position (to the right of the search form).
Here is the original nav:
<nav class="navbar navbar-inverse" 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 collapsed" data-toggle="collapse" data-target="#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="/"><span class="logo">logo</span></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="dropdown">
Actions <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action 1</li>
<li>Action 2</li>
</ul>
</li>
<li>Posts</li>
<form class="navbar-form navbar-left search-form" role="search" action="/home/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
<div class="form-group">
<input type="text" name="q" id="q" class="form-control" placeholder="Search">
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
</div>
</form>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" id="notification-circle" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i title="Notifications" class="fa fa-circle fa-lg"></i>
</a>
<ul class="dropdown-menu" id="notifications-ul">
<li>All Notifications...</li>
</ul>
</li>
<li>Help</li>
<li>Logout</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Currently this nav gets collapsed on xs devices, and that is a problem, because the notifications button will light up with a number when there are new notifications, and that information will not show up to the user if the notification is collapsed.
Attempt 1:
I tried to move the notifications into the navbar-header, but that renders the notifications to the left of the search, which is not acceptable.
Attempt 2:
I also tried to create two notifications - one visible in xs in the header, one hidden in xs, but it causes all kind of weirdnesses - the dropdown list item shows as a separate circle in the mobile view, for example. Here is one variant of my attempt:
<nav class="navbar navbar-inverse" 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 collapsed" data-toggle="collapse" data-target="#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="/"><span class="logo">logo</span></a>
<ul class="navbar-brand visible-xs-inline">
<li class="dropdown">
<a href="#" id="notification-circle" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i title="Notifications" class="fa fa-circle fa-lg"></i>
</a>
<ul class="dropdown-menu" id="notifications-ul">
<li>All Notifications...</li>
</ul>
</li>
</ul>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="dropdown">
Actions <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action 1</li>
<li>Action 2</li>
</ul>
</li>
<li>Posts</li>
<form class="navbar-form navbar-left search-form" role="search" action="/home/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
<div class="form-group">
<input type="text" name="q" id="q" class="form-control" placeholder="Search">
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
</div>
</form>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Help</li>
<li>Logout</li>
</ul>
<ul class="nav navbar-nav navbar-right hidden-xs">
<li class="dropdown">
<a href="#" id="notification-circle" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i title="Notifications" class="fa fa-circle fa-lg"></i>
</a>
<ul class="dropdown-menu" id="notifications-ul">
<li>All Notifications...</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Here is the bootply link: http://www.bootply.com/SZbrMZoiXq
How can I make the notifications dropdown not collapse in mobile devices?
For instance, is there a class in bootstrap that skips collapse like 'no-collapse' that I can apply to the nav I want to skip collapsing?

Twitter Bootstrap 3.3.5 navbar drop-down pull-right

I am trying to make the drop-down go to the extreme right, after the search input and submit button, tried pull-right, navbar-right but to no avail.
Is there a way to achieve this?
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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 class="active">Home</li>
<li>About</li>
<li>Contact</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>
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
Login <span class="caret"></span>
<ul class="dropdown-menu">
<li>Facebook</li>
<li>Twitter</li>
<li>Google</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
I'm trying this:
Really not sure, but what it does if you change the login part ul from:
<ul class="nav navbar-nav pull-right">
to:
<ul class="nav navbar-right pull-right">
You need to make the links after the search form :
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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">
<form class="navbar-form" 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">
<li class="dropdown">
Login <span class="caret"></span>
<ul class="dropdown-menu">
<li>Facebook</li>
<li>Twitter</li>
<li>Google</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
And this is the CSS for it :
#navbar{
float:right !important;
}
.navbar-form{
display:inline-block;
float:left;
}
Here's the JSFiddle
Note : For the mobile version , you only need to make this under the right media query :
#navbar{
float:none !important;
}