I am currently using bootstrap with my website and am trying to take advantage of the responsive features, one of which is the navbar button on smaller screens/devices. Now I have made some changes to the navbar, one of which is centering it rather than the default float left and it looks like this:
<div class="navbar navbar-fixed-top center">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse">
<ul class="nav">
<li class =active >Home</li>
<li class="dropdown" id="menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu">Our Services<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Registered Care</a></li>
<li>Supported Living</a></li>
<li>Vocational Services</a></li>
<li>Outreach Support</a></li>
<li>Day Activities</a></li>
<li>Therapeutic Services</a></li>
</ul>
</li>
<li class="dropdown" id="menu1">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu1">Our Homes<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Ty Newydd</a></li>
<li>Sandpiper</a></li>
<li>Woodside</a></li>
</ul>
</li>
<li class="dropdown" id="menu2">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu2">Our Team<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Our Team</a></li>
<li>Staff Vacancies</a></li>
</ul>
</li>
<li class = >Gallery</li>
<li class = >FAQ</li>
<li class = >News</li>
<li class="dropdown" id="menu4">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu4">Feedback<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Quality Reports</a></li>
<li>Care Standards</a></li>
<li>Testimonials</a></li>
</ul>
</li>
<li class = >Contact Us</li>
<li class="dropdown" id="menu3">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu3">Login<b class="caret"></b></a>
<ul class="dropdown-menu">
<div id="loginbox">
<form accept-charset="UTF-8" action="/users/sign_in" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="5174LhGldMFczTwLf9sB+I5NKs3I0rLxGoA6xq1GKKs=" /></div>
<div><label for="user_email">Email</label><br />
<input id="user_email" name="user[email]" size="30" type="email" value="" /></div>
<div><label for="user_password">Password</label><br />
<input id="user_password" name="user[password]" size="30" type="password" /></div>
<div><input name="user[remember_me]" type="hidden" value="0" /><input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1" /> <label for="user_remember_me">Remember me</label></div>
<div><input name="commit" type="submit" value="Sign in" /></div>
</form>
</div>
</ul>
</li>
</div>
</div>
</ul>
</div>
</div>
</div>
For a live example you can visit
http://46.32.253.11/ .
I'm guessing as I have centered everything in my navbar then it has carried across into the nav.collapse, but I am unsure on how to get it to behave in the default way without effecting my navbar. What I would like is to have all the links align to the left within the navbar button instead of all in the center as they currently are
Whilst on the subject of the nav collapse, does any one know of any ways to customise it, for example list all the headings and then perhaps click to reveal all sub headings? Just a thought there. Anyway if anyone can offer any assistance with this it would be much appreciated
Apply your override with a media query
#media (min-width: 768px) {
.navbar.center {
...
}
}
The navbar will be centered from 768px and after.
Related
I'm having a problem with my navbar that I'm making with bootstrap.
search form has a lot of unused space behind it, how could I get rid of it?
Can I make navbar to collapse as soon at it would make 2 line navigation bar?
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<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="index.php"> Name </a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown">
<span class="glyphicon glyphicon-folder-open" style="color: white"></span> <img src="img/flags/country.png"> <b class="caret"></b>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">something
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">something
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">something
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-user" style="color: white"></span>admin
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right form-inline">
<span class="label label-default">label 1</span>
<div class="input-group col-sm-2">
<input type="text" class="form-control input-sm" style="border-radius: 10px 0 0 10px;">
<div class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit" style="border-radius: 0 10px 10px 0;">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
<span class="label label-default">label 2</span>
<div class="input-group col-sm-2">
<input type="text" class="form-control input-sm" style="border-radius: 10px 0 0 10px;">
<div class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit" style="border-radius: 0 10px 10px 0;">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
<span class="label label-default">label 3</span>
<div class="input-group col-sm-2">
<input type="text" class="form-control input-sm" style="border-radius: 10px 0 0 10px;">
<div class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit" style="border-radius: 0 10px 10px 0;">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
</div>
</nav>
https://jsfiddle.net/nooorz24/ove78e91/1/
The nav bar will collapse depending on the screen size you set. Right now you are linking to the CDN, so you would have to override the #media sections of the CSS.
The extra space will need to be overridden too. It looks like it's in the stylesheet here:
#media (min-width: 768px)
navbar.less:385
.navbar-right {
float: right!important;
margin-right: -15px;
}
How to make 100% width of the search input in navbar?
The field is limited in width:
<nav class="navbar navbar-light navbar-dark bg-inverse">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
<ul class="nav navbar-nav pull-xs-right">
<li class="nav-item">
<form class="form-inline ">
<input class="form-control" type="text" placeholder="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</li>
<li class="nav-item">
<a class="nav-link" href="#">User Name</a>
</li>
</ul>
</nav>
Here is the fiddle:
https://jsfiddle.net/Dieselnick/tdoz2o4d/
Updated 2019
As of Bootstrap 4 the Navbar is flexbox so creating a full-width search input is easier. You can simply use w-100 and d-inline utility classes:
<form class="mx-2 my-auto d-inline w-100">
<div class="input-group">
<input type="text" class="form-control" placeholder="...">
<span class="input-group-append">
<button class="btn btn-outline-secondary" type="button">GO</button>
</span>
</div>
</form>
http://www.codeply.com/go/sbfCXYgqoO
Here's another example with the search input outside of the collapsing navbar:
<!-- search input not in navbar collapse -->
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="d-flex flex-grow-1">
Codeply
<form class="mr-2 my-auto w-100 d-inline-block order-1">
<div class="input-group">
<input type="text" class="form-control border border-right-0" placeholder="Search...">
<span class="input-group-append">
<button class="btn btn-outline-light border border-left-0" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</form>
</div>
<button class="navbar-toggler order-0" type="button" data-toggle="collapse" data-target="#navbar7">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse flex-shrink-1 flex-grow-0 order-last" id="navbar7">
<ul class="navbar-nav">
..
</ul>
</div>
</nav>
http://www.codeply.com/go/sbfCXYgqoO
And, finally another example that varies the width of the search on desktop/mobile (only full width on mobile) from my answer here
Bootstrap 3 (original answer)
You can use the text-truncate hack on the last navbar li like this..
<li class="text-truncate">
<form class="input-group">
<input class="form-control" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus" type="text">
<div class="input-group-btn">
<button class="btn btn-outline-success" type="submit">Search</button>
</div>
</form>
</li>
In Bootstrap 4, text-truncate will set:
overflow: hidden;
white-space: nowrap;
This enables the search form to fill the remaining width and not wrap.
Demo http://www.codeply.com/go/22naSu3c0E
Another option is to use table-cell:
<form>
<div class="table-cell"> </div>
<div class="table-cell fill-width">
<input class="form-control" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus" type="text">
</div>
<div class="table-cell">
<button class="btn btn-outline-success" type="submit">Search</button>
</div>
</form>
http://www.codeply.com/go/JdbPvotSXg
I'm trying display some elements positioned in the center (like dropdown list) of nav bar. But my radio buttons doesn't want to get offset. What should I add to my code?
<nav class="navbar navbar-default navbar-fixed-top second-navbar" role="navigation">
<div class="container-fluid">
<ul class="nav navbar-nav">
<li class="container">
<form role="form">
<label class="radio-inline"><input type="radio" name="gr" value="0" onchange="val(this)">Popular first</label>
<label class="radio-inline"><input type="radio" name="gr" value="1" onchange="val(this)">Newest first</label>
</form>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button">
Items per page: <b>#Model.PagingInfo.ItemsPerPage</b>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>5</li>
<li>10</li>
<li>20</li>
</ul>
</li>
</ul>
</div>
</nav>
You need to add div with class radio. also you need to remove unnecessary tags
<nav class="navbar navbar-default navbar-fixed-top second-navbar" role="navigation">
<div class="container-fluid">
<ul class="nav navbar-nav">
<li class="radio">
<label class="radio-inline">
<input type="radio" name="gr" value="0" onchange="val(this)">Popular first</label>
<label class="radio-inline">
<input type="radio" name="gr" value="1" onchange="val(this)">Newest first</label>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button">
Items per page: <b>#Model.PagingInfo.ItemsPerPage</b>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>5</li>
<li>10</li>
<li>20</li>
</ul>
</li>
</ul>
</div>
Here is the codepen : http://codepen.io/anon/pen/MKqwgJ
There is slight change in your markup buddy. Just do these listed changes and it will be perfect as you wanted.
1.) remove the class container from your <ul> tag.
2.) To move the radio button to the left, add this bootstrap class to the radio button <li> tag.
<li class="navbar-left">
3.) To move the dropdown to the right, add this bootstrap class to the dropdown <li> tag.
<li class="dropdown navbar-right">
4.) Now for the top spacing, you need to give some padding to the radio button form just like the one dropdown list has.
form {
padding: 10px 15px;
}
Voila ... perfectly aligned ! Here is the JSFiddle
<header class="navbar navbar-static-top bs-docs-nav" id="top" role="banner">
<div id="header" class=" container-fluid">
<div class="navbar-header">
<button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Menu</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img title="DropInn" src="logo/logo.png" width="137" height="45">
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
<div class="search" style="">
<form id="search_form1" action="http://products.cogzidel.com/airbnb-clone/search" method="post" class="searchform_head">
<i class="fa fa-search heaericon"></i>
<input type="text" id="searchTextField" name="searchbox" class="searchbox" value="Where are you going?" onblur="if (this.value == ''){this.value = 'Where are you going?'; }" onfocus="if (this.value == 'Where are you going?') {this.value = ''; }" onKeyPress="return disableEnterKey(event)" placeholder="Where are you going?" />
<div id="map-canvas"></div>
<input type="hidden" id="lat" name="lat" value="">
<input type="hidden" id="lng" name="lng" value="">
<div class='advanced_search' id="advanced_search" style='display: none; position: absolute;
z-index: 2147483647; background:#FCFCFC; border: 1px solid #CCCCCC; padding: 10px; opacity: 1;width: 240px;top:37px;'>
<label class="checkin_search">
Check in
<div id="checkinWrapper" class="input-wrapper">
<input id="checkindate2" class="check_wrap checkin search-option ui-datepicker-target" type="text" placeholder="Check in" name="checkin" autocomplete="off" readonly>
</div>
</label>
<label class="checkout-detail_search">
Check out
<div id="checkoutWrapper" class="input-wrapper">
<input id="checkoutdate2" class="check_wrap checkout search-option ui-datepicker-target" type="text" placeholder="Check out" name="checkout" autocomplete="off" readonly>
</div>
</label>
<div class="clearfix"></div>
<p class="filter_header">Room type</p>
<!-- Search filter content is below this -->
<div class="clearfix"></div>
<ul class="search_filter_content">
<li class="clearfix checkbox">
<input class="checkbox_filter" type="checkbox" value="Entire home/apt" name="room_types1" id="room_type_0">
<label class="checkbox_list" for="room_type_0"> Entire home/apt</label>
</li>
<li class="clearfix checkbox">
<input class="checkbox_filter" type="checkbox" value="Private room" name="room_types2" id="room_type_1">
<label class="checkbox_list" for="room_type_1"> Private room</label>
</li>
<li class="clearfix checkbox">
<input class="checkbox_filter" type="checkbox" value="Shared room" name="room_types3" id="room_type_2">
<label class="checkbox_list" for="room_type_2">Shared room</label>
</li>
</ul>
<div class="clearfix"></div>
<!-- <button id="submit_location" class="btn_dash" style=" font-size: 12px;margin: 10px 0; padding: 5px 11px;" type="submit" value="Search" name="Submit" >-->
<!--<i class="fa fa-search submitloc"></i>-->
<!--<img src="http://products.cogzidel.com/airbnb-clone//css/templates/blue/images/search_icon1.png" />-->
<button id="submit_location" class="btn_dash" type="submit" value="Search" name="Submit">
<i class="fa fa-search submitloc"></i>
<!--<img src="http://products.cogzidel.com/airbnb-clone//css/templates/blue/images/search_icon1.png" />-->
Find A Place </button>
<label class="btn_dash" id="close_search">
Close </label>
</div>
</form>
</div>
</li>
</form>
</li>
<li id="subnavigation" class="dropdown browse-dropdown">
<a class="dropdown-toggle header_link" href="#" data-toggle="dropdown">Browse <span class="caret"></span></a>
<ul class="dropdown-menu sub-menu browse-submenu">
<li><!-- <i class="icon-popular"> </i>--> <i class="fa fa-heart"></i> Popular</li>
<li><a class="friends" href="home/friends/index.html"><i class="icon-friends"> </i> Friends</a></li>
<li><a class="map-neigh" href="home/neighborhoods/index.html"><!--<i class="icon-neighborhoods"> </i> --> <i class="fa fa-map-marker"></i>Neighborhoods</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="rightsign sign1">Sign Up</li>
<li class="rightsign sign1">Sign In</li>
<li id='view_help' style='float:left;'>
<li id='view_help' class="dropdown browse-dropdown help_book">
<a class="dropdown-toggle view_help1" data-toggle="dropdown" href="#">Help <span class="caret"></span></a>
<ul class="dropdown-menu sub-menu browse-submenu">
<li>How do i sign up?</li>
<li> Need help on this page?
</li>
</ul>
</li>
<li class="lisyourspace"> <a class="btn yellow" href="rooms/new.html"><span>List Your Space</span></a> </li>
<!--<li class="listyourspace_menu"> <a class="yellow btn" href="http://products.cogzidel.com/airbnb-clone/rooms/new"><span>List Your Space</span></a> </li>-->
</nav>
</div>
</header>
I need CSS code for this display exact like Airbnb home page. Somebody please help to get this. I tried so many times, but failed to design that properly. How to do the full width grid system and how to code the CSS files?
First, you should try to add your background elements. Then, use basic css to make it fit the whole page width with repeat or not (depending on your background image)
Then, about the "full width grid system", bootstrap has many classes that fit your requirements like 'col-lg-** col-md-** col-sm-** col-xs-**', you should have a look at this :
http://getbootstrap.com/css/#grid
Your code is just a bit too generic. But this "bootply" is a good starting point for you :
http://www.bootply.com/b1SPDA3GOn
Hope it helps!
I've started using Twitter Bootstrap, and have implemented a responsive nav that changes to a foldable menu if viewed in on a mobile (or shrinking the browser windows width).
This is how it looks right now:
What I want is the menu items to be listed under each other left of the login form, instead of horisontal as it is now. Is there an easy way to do this with Twitter Bootstrap?
Here's my nav code: (I haven't changed the original css):
<div class='navbar'>
<div class='navbar-inner'>
<div class='container-fluid'>
<button type="button" class="btn btn-navbar" 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='brand'>Test</a>
<ul class='nav nav-collapse collapse'>
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
<li><a>Item 2</a></li>
<li><a>Item 2</a></li>
</ul>
<ul class='nav nav-collapse collapse pull-right'>
<li class=""><form class="navbar-search">
<input type="text" class="span2" placeholder="Login">
<input type="text" class="span2" placeholder="Password">
<input type="submit" value="Login" class="btn"/>
</form></li>
</ul>
</div>
</div>
</div>
Since the LI's are probably floated or defined as inline-block, you need to change their CSS rule to clear:both or display:block respectively. Then you need to float the entire menu to the left, and the login form to the right.
You can make those changes responding to the resize event, using JQuery's css method
Per the twitter bootstrap docs everything that you want hidden and formatted correctly needs to be put within <div class="nav-collapse collapse">{your nav items}</div>
<div class='navbar'>
<div class='navbar-inner'>
<div class='container-fluid'>
<button type="button" class="btn btn-navbar" 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='brand'>Test</a>
<!-- ALL MY NAVIGATION IN HERE -->
<div class='nav-collapse collapse'>
<ul class='nav'>
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
<li><a>Item 2</a></li>
<li><a>Item 2</a></li>
</ul>
<form class="navbar-search pull-right">
<input type="text" class="span2" placeholder="Login">
<input type="text" class="span2" placeholder="Password">
<input type="submit" value="Login" class="btn"/>
</form>
</div>
</div>
</div>
</div>
Just moving your html around without adding any css or javascript will do the trick.:)
Here is a jsfiddle for it: http://jsfiddle.net/hajpoj/Z3wqL/3/