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%;
}
Related
I would like to switch the brand and the toggle button in mobile view if the viewport is small enough. On desktop viewport the brand icons shall be on the right side and the links shall be displayed normaly.
Examples:
Desktop:
+--------------------------------------------+
|Link1 Link2 BrandIcon1 BrandIcon2 |
+--------------------------------------------+
Mobile:
+----------------------------+
|[=] BrandIcon1 BrandIcon2 |
+----------------------------+
What is the easiest and cleanest way to code this?
Made a Pen: http://codepen.io/Kaito23/pen/Wxmxgm
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
.navbar-toggle {
float:left;
}
.navbar-brand {
float: right;
}
<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="#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>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-left">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
</ul>
<ul class="visible-xs visible-xs visible-sm visible-md visible-lg nav navbar-nav navbar-right">
<li><img src="http://images.fatcow.com/icons/32/wordpress.png" /></li>
<li><img src="http://www.wbdesignideas.com/images_drf_color.png" /></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
Currently the problem is that when the icons are in the navbar-collapse class they disapear. If I put them under the collapse div, they are in a
new row.
Thanks in advance
Greetings
Kaito
Let's take Bootstrap's default navbar and remove unnecessary parts.
Then change floats to the opposite direction.
And add second brand before the first one. (It's because of the float: right; property.)
Please check the result: http://codepen.io/glebkema/pen/PzLbmz
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
#media (min-width: 768px) {
.navbar-header {
float: right;
}
}
.navbar-brand {
float: right;
}
.navbar-toggle {
float: left;
margin-left: 15px;
margin-right: 0;
}
<nav class="navbar navbar-default">
<div class="container">
<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="#">Brand 2</a>
<a class="navbar-brand" href="#">Brand 1</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Left 1</li>
<li>Left 2</li>
<li>Left 3</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
I have a navbar in which the width does not fit 100% when the browser is resized less than 760px
<nav class="navbar navbar-inverse navbar-static-top" style="margin-bottom:0;">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<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" href="#">
<img src="#">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-collapse collapse" id="bs-example-navbar-collapse-1" style="height: 1px;">
<ul class="nav navbar-nav navbar-left">
<li class="hidden"></li>
<li class="divider-vertical"></li>
<li>Home</li>
<li class="divider-vertical"></li>
<li>Login</li>
<li class="divider-vertical"></li>
<li>Signup</li>
<li class="divider-vertical"></li>
<li>
<form action="#">
Request
</form>
</li>
<li class="divider-vertical"></li>
<li><a target="_blank" href="#"></a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
Here are some custom css i used
#media (min-width: 760px) {
.container {
padding-left: 20px;
padding-right: 20px;
width: auto
}
}
Add this CSS:
#media (max-width: 760px){
.container {
width: 100%;
}
}
.container-fluid>.navbar-collapse, .container-fluid>.navbar-header, .container>.navbar-collapse, .container>.navbar-header {
margin-right: 0;
margin-left: 0;
}
Here is a fiddle for it https://jsfiddle.net/u27r6dL2/3/
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 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;
}
I have the following HTML for my menu
<nav id="site-navigation" class="main-navigation navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-inner">
<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>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav nav-menu" aria-expanded="false">
<li>Home</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Shop</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</nav>
This is the HTML as Bootstrap suggests u use so the menu wil be responsive when resizing. Currently it looks like this
The problem is that i want the <li> items to justify depending on the width.
Bootstrap has .nav-justified for this but when I do that is doesn't show properly and it floats all the <li> items to the left.
That looks like this
How can I make the menu items justify?
Replace the navbar-nav class on the ul.nav element with nav-pills (or nav-tabs).
<ul class="nav nav-pills nav-menu" aria-expanded="false">
<li>Home</li>
<li>Portfolio</li>
<!-- etc. -->
</ul>
See: http://getbootstrap.com/components/#nav
Yep i had this problem before, all you have to do is change the % width of the class, you have to specify the width as the default has the width at 1%
.nav-justified>li {
display: table-cell;
width: 15%;
}