This question already has answers here:
Consolidate multiple Bootstrap 3 navbar menus on collapse
(1 answer)
Bootstrap NavBar with left, center or right aligned items
(14 answers)
Closed 5 years ago.
My codes are working fine on mobile view but on desktop right side Links are getting out of nav-bar. i am trying to create nav bar with Brand in center, search bar on left and links on right. and how to move hambuger bar on left and search on right side on mobile view .. (sorry for my english)
.navbar-brand {
position: absolute;
width: 100%;
left: 0;
top: 0;
text-align: center;
margin: auto;
}
.navbar-toggle {
z-index:3;
}
<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>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-2">
<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>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"><span class="glyphicon glyphicon-search" aria-hidden="true"> </span>
</button>
</div>
<div class="collapse navbar-collapse navbar-left" id="navbar-collapse-1">
<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>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-2">
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</nav>
#media (max-width: 768px) {
.nav_bar_align .navbar-brand{
position: absolute;
width: 100%;
left: 0;
top: 0;
text-align: center;
margin: auto;
}
.nav_bar_align .nav_humber{
float: left;
margin-left: 15px;
z-index: 1;
}
}
<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>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top nav_bar_align" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle nav_humber" data-toggle="collapse" data-target="#navbar-collapse-2">
<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>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"><span class="glyphicon glyphicon-search" aria-hidden="true"> </span>
</button>
</div>
<div class="collapse navbar-collapse navbar-left" id="navbar-collapse-1">
<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>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-2">
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</nav>
add menu-1 class or call it whatever you want to the button
<button type="button" class="navbar-toggle menu-1" data-toggle="collapse" data-target="#navbar-collapse-2">
then add this to your css:
.menu-1 {
float: left;
margin-left: 10px;
}
Update: to handle search issue remove width: 100 and increase left for .navbar-brand like this:
.navbar-brand {
position: absolute;
/*width: 100%;*/
left: 50%;
top: 0;
text-align: center;
margin: auto;
}
and add this css also:
#media (max-width:767px){
a.navbar-brand {
left: 45%;
}
}
check the updated Jsfiddle
Related
What I'm experiencing difficulty is that my navbar-right elements won't align with my navbar-brand part. I need help with this. I want to align them but the element would be like this
header.html
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<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="#">
{{ Html::image('assets/images/logo.png') }}
</a>
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li class="">About Us</li>
</ul>
</div>
</div>
</header>
style.css
.navbar-text > a {
color: inherit;
text-decoration: none;
}
body {
padding-top: 70px;
padding-bottom: 100px;
}
.navbar-default{
background-color:#005b96;
border-color:#005b96;
font-family: 'Roboto', sans-serif;
font-size: 15px;
position:absolute;
top: 25px;
left:100px;
right:100px;
}
.navbar-brand {
width: 100px;
height: 50px;
}
.navbar-default .navbar-brand > img {
width: 130px;
height:50px;
position: absolute;
top: 5px;
padding-top:5px;
padding-bottom: 5px;
margin-left: auto;
}
.row{
position:absolute;
top: 25px;
left:115px;
right:115px;
}
.panel{
margin-top:100px;
}
Example. The issue is actually with your markup. Your .container should also wrap
<div class="navbar-collapse collapse">
......
</div>
Like so:
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<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="#">
{{ Html::image('assets/images/logo.png') }}
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li class="">About Us</li>
</ul>
</div>
</div>
</div>
</header>
Is this your desired result? http://screencast.com/t/5drms5A0f
If yes, here is how I achieved that:
.navbar-collapse.collapse {
position: absolute;
right: 50px;
top: 26px;
}
Also, I would put that in min 768 px media query.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to figure out how to make the search box fixed in the navigation bar instead of being part of the dropdown menu. The final output would be something similar to the image below.
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- add menu -->
<div class="collapse navbar-collapse" id="navbar1">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
</ul>
<!-- add search form -->
<form class="navbar-form navbar-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search this site">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
</div>
Here's the code I'm currently working on: http://www.bootply.com/fb311f2zSJ#
Try this:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
/* CSS used here will be applied after bootstrap.css */
.navbar-header form {
position: absolute;
right: 20px;
max-width: 250px;
}
button.navbar-toggle.pull-left {
margin-left: 15px;
}
#media only screen and (max-width:768px){
.navbar-inverse .navbar-collapse, .navbar-inverse .navbar-form {
border-color: rgba(0,0,0,0);
margin-top: 0;
padding-top: 8px;
}
.navbar-form {
padding: 10px 15px;
margin-top: 8px;
margin-right: -15px;
margin-bottom: 8px;
margin-left: -15px;
border-top: 0px solid transparent;
border-bottom: 0px solid transparent;
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.1),0 1px 0 rgba(255,255,255,.1);
box-shadow: inset 0 1px 0 rgba(255,255,255,.1),0 0px 0 rgba(255,255,255,.1);
}
}
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle pull-left" data-toggle="collapse" data-target="#navbar1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- add search form -->
<form class="navbar-form navbar-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search this site">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
<!-- add menu -->
<div class="collapse navbar-collapse" id="navbar1">
<ul class="nav navbar-nav" style="width:100%">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
You will have to add another search form that will become visible on mobile devices. You can style it with your css to position the search bar properly.
Here is the updated html:
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle pull-left" data-toggle="collapse" data-target="#navbar1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- add the mobile devices search form here -->
<div class="col-xs-10 visible-xs">
<form class="navbar-form navbar-right mobile-search" role="search">
<div class="input-group">
<input class="form-control" placeholder="Search this site" type="text">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
<!-- end of the mobile devices search form section -->
</div>
<!-- add menu -->
<div class="collapse navbar-collapse" id="navbar1">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
</ul>
<!-- add search form -->
<form class="navbar-form navbar-right hidden-xs" role="search">
<div class="input-group">
<input class="form-control" placeholder="Search this site" type="text">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
</div>
I have done some changes in default css file may this will help you.
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header pull-left">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- add menu -->
<div class="collapse navbar-collapse" id="navbar1">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
</ul>
<!-- add search form -->
</div>
<form class="navbar-form navbar-right pull-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search this site">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
</nav>
CSS:
#media (min-width:768px){
.navbar-collapse{
float:left
}
}
#media (max-width:767px){
.navbar-form.navbar-right{
border-color: #101010;
width: calc(100% - 30px);
padding: 0;
border: none;
}
.navbar{
border:none;
}
.navbar-collapse{
background-color: #222;
position: absolute;
top: 50px;
width: 100%;
left:0;
margin:0 !important;
}
}
Here is working demo: https://jsfiddle.net/vb8ptav5/
I am new to bootstrap.
I try to make a navbar that contains a form and navigation.
I would like to shrink the input field in certain screen sizes.
Right now it looks like this.
This is OK:
In these cases I want to shrink the input field:
Relevant HTML code:
<nav 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" 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="#">Site Name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" placeholder="Email" class="form-control">
</div>
<button type="submit" class="btn btn-success">Subscribe</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>News</li>
<li>Contact</li>
<li class="dropdown">
Dropdown Menu <span class="caret"></span>
<ul class="dropdown-menu">
<li>First Menu Item</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
How can I achieve this?
Thank you.
You can use this CSS:
.navbar-form .form-control {
width: 100px; // your width
}
#media (min-width: 768px) {
.navbar-form .form-control {
width: 150px; // your width
}
}
Do these changes
In HTML:
<ul id="navbarRight" class="nav navbar-nav navbar-right">
Instead of
<ul class="nav navbar-nav navbar-right">
above is the last.
And add this CSS
#navbar{
width: 100%;
}
form{
max-width: 45%;
}
#navbarRight{
max-width: 55%;
}
I have a nabvar that contains a search field 'navbarSearchQuery'. When the navbar collapses when the screen shrinks to a phone size I want 'navbarSearchQuery' to remain visible in the navbar. Is there something I can do with #media queries to keep it visible or do I have to move it outside the collapsable section in the navbar?
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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 hidden-xs" href="/Home">Yoga</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
Browse <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Popular
</li>
<li>Friends
</li>
<li>Groups
</li>
<li>Neighborhoods
</li>
<li>About <span class="sr-only">(current)</span>
</li>
<li>Contact
</li>
</ul>
</li>
<li>
<div class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" id="navbarSearchQuery" name="location">
</div>
</div>
</li>
</ul>
#Html.Partial("_LoginPartial")
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
You can create a form inside the navbar-header.
/**Custom**/
.navbar.navbar-custom {
height: 50px;
border: none;
}
.navbar-custom .formSearch {
width: 300px;
float: left;
display: block;
position: absolute;
padding-top: 7px;
margin-left: 160px;
}
.navbar-custom .inner-addon {
position: relative;
}
.navbar-custom .inner-addon .glyphicon {
position: absolute;
padding: 10px;
pointer-events: none;
color: black;
}
.navbar-custom .left-addon .glyphicon {
left: 0px;
}
.navbar-custom .left-addon input {
padding-left: 30px;
}
#media (max-width: 767px) {
.navbar-custom .formSearch {
padding-left: 15px;
width: 70%;
margin-left: 0;
}
.navbar-custom .navbar-collapse {
background: #f5f5f5;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/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 navbar-custom">
<div class="container-fluid">
<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 hidden-xs" href="/Home">Yoga</a>
<form class="formSearch" role="search">
<div class="inner-addon left-addon"> <span class="glyphicon glyphicon-search"></span>
<input type="text" class="form-control" placeholder="Search" id="navbarSearchQuery" name="location">
</div>
</form>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown"> Browse <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Popular
</li>
<li>Friends
</li>
<li>Groups
</li>
<li>Neighborhoods
</li>
<li>About <span class="sr-only">(current)</span>
</li>
<li>Contact
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
I can put the navbar in the header part but when I shrink the alignment is slightly off. Can this be fixed?
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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 hidden-xs" href="/Home">Yoga</a>
<div class="navbar-form navbar-left navbar-search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" id="navbarSearchQuery" name="location">
</div>
</div>
</div>
before and after pics. you can see the button isn't aligned correctly
I need to align the menu text with the bottom of the Bootstrap 3 navbar.
My code is:
<nav class="navbar navbar-default">
<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>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img class="img-responsive" src="/assets/img/outa.png" width="120px;"/></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav pull-right">
<li>Saved searches</li>
<li>Settings</li>
<li>About</li>
<li>Sign In</li>
</ul>
</div>
</div>
</nav>
This centers the menu vertically in the shaded navbar. Is it possible to change this so that the menu lies 4px above the bottom of the shaded navbar area?
This should do the trick.
#myNavbar {
position: relative;
}
#myNavbar .nav {
position: absolute;
bottom: 0;
right: 0;
margin-bottom: -10px;
}
JSFiddle