Twitter Bootstrap - center navbar when responsive to two rows - css

I have a navbar with a bunch of dropdowns. When the navbar is on one row (full size screen), I got it to be centered. When the screen size is small, I successfully made it collapse into a button, which is centered. However, when the screen size is medium and the navbar is on two rows, neither row is centered. How do I fix this?
Here is the jsFiddle: http://jsfiddle.net/grzt/US2sS/
You can resize the jsFiddle lower-right frame to see the different screen size results I mentioned above.
HTML:
<nav class="navbar navbar-inverse">
<div class="container-fluid" style="text-align: center;">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-navbar-collapse" id="navigation-collapse-btn">
<div id="navigation-collapse-text">Navigation</div>
<span class="sr-only">Toggle navigation</span>
</button>
<div class="collapse navbar-collapse" id="navigation-navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
<li class="dropdown">
Some Words <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
CSS:
.navbar-nav {
/*center navbar inner elements*/
display: inline-block;
float: none;
}
.navbar-toggle
{
/*center collapse button*/
float:none;
}

If you want to keep menu in center avoid using float. Check if this helps you.
#media (min-width: 768px) {
.navbar-nav>li {
float: none;
display: inline-block;
}
}

Related

nav-right contents in bootstrap not getting fit in ipads

Contents in right side on nav bar is not seen in iPads , but visible in web page.
I tried to add a css for this
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
body {
width: 495px;
}
.navbar-fixed-top,
.navbar-fixed-bottom,navbar-right {
position: fixed;
margin-left: 0px;
margin-right: 0px;
}
}
But this doesn't bring any change
I am new to Bootstrap , Please help me to resolve in a best possible way.
<div id="head-nav" class="navbar navbar-default 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="fa fa-gear"></span>
</button>
<a class="navbar-brand" href="#"><span><img src="../images/imagesj/logotype.png"
alt="enviroManager" width="144"></span></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="<c:url value="/enviro/home.htm" />" class="dropdown-toggle"
data-toggle="dropdown"><fmt:message key="homeMenu" /> <b class="caret"></b></a>
<ul class="dropdown-menu col-menu-2">
<li class="col-sm-6 no-padding">
<ul>
<li class="dropdown-header"><i class="fa fa-eye"></i><fmt:message key="menu.views" /></li>
<li>Dashboard</li>
<li>Groups</li>
<li>Users</li>
</ul>
</li>
<li class="col-sm-6 no-padding">
<ul>
<li>Modules</li>
<li>User Domains</li>
<li>Licences</li>
<li>Questions</li>
<li>Software Change Log</li>
</ul>
</li>
</ul>
</li>
<ul class="nav navbar-nav navbar-right user-nav" >
<li class="dropdown profile_menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img alt="Avatar" src="../images/imagesj/avatar2.jpg" /><span><c:out value="${uName}"/></span>
<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>My Account</li>
<li>Profile</li>
<li>Messages</li>
<li class="divider"></li>
<li>Sign Out</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right user-nav">
<li class="dropdown profile_menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-globe"></i>
<span> Languages </span> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Current Locale : ${pageContext.response.locale}</li>
<li class="divider"></li>
<li>English</li>
<li><a href="<c:out value="${landingPage}" />?language=span">Spanish
<span class="flag-icon flag-icon-es"></span></a></li>
<li><a href="<c:out value="${landingPage}" />?language=fr">French
<span class="flag-icon flag-icon-fr"></span></a></li>
<li><a href="<c:out value="${landingPage}" />?language=zh_CN"> Chinese
<span class="flag-icon flag-icon-cn"></span></a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>

Bootstrap 3 navigation dropdown stopped working

I haven't changed any code on prod and qa but for some reason my qa collapse nav has stopped working pasting both the code here since I can't figure out what's wrong, I checked the console for error if any but its showing nothing, i even compared both the codes and it shows all is fine.
PROD WORKING
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li>Daily Experience</li>
<li>Attendance Records</li>
<li>Photos</li>
<li>School Info</li>
<li class="dropdown">
<a data-toggle="dropdown" style="padding-top: 21px; padding-bottom: 11px; !important" class="dropdown-toggle" href="#">History <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Daily Experience</li>
<li>Attendance Records</li>
</ul>
</li>
<li>Profile</li>
<li class="dropdown">
<a data-toggle="dropdown" style="padding-top: 21px; padding-bottom: 11px; !important" class="dropdown-toggle" href="#">Select Child <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Annett Joy</li>
<li>Charlotte Pinkiewicz</li>
</ul>
</li>
<li>Change Password</li>
<li>Logout</li>
</ul>
</div>
QA NOT WORKING
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li>Daily Experience</li>
<li>Attendance Records</li>
<li>Photos</li>
<li>School Info</li>
<li class="dropdown">
<a data-toggle="dropdown" style="padding-top: 21px; padding-bottom: 11px; !important" class="dropdown-toggle" href="#">History <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Daily Experience</li>
<li>Attendance Records</li>
</ul>
</li>
<li>Profile</li>
<li class="dropdown">
<a data-toggle="dropdown" style="padding-top: 21px; padding-bottom: 11px; !important" class="dropdown-toggle" href="#">Select Child <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Annett Joy</li>
<li>Charlotte Pinkiewicz</li>
</ul>
</li>
<li>Change Password</li>
<li>Logout</li>
</ul>
</div>
This is a screenshot of my Network tab
Everything is just fine in your code but I'm sure that your jQuery library doesn't loaded correctly. Make sure that jQuery script is included on the page as well as it present on specified path. Then it will work fine.
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
Here is the demo of QA code after including jQuery reference.
JS Fiddle Demo
Bootstrap.js was getting loaded twice for some reason so i removed it once and it started working.

How can I have two Bootstrap navbars on the same page of different heights?

Using Bootstrap 3.0 with two navbars on the same page. The height variable will adjust both .navbar blocks. I've tried adding another class to override the height of the first navbar, but its left unaffected.
Bootply example
HTML:
<!-- Site Tools and Search Navbar -->
<div class="navbar siteTools">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control input-sm" placeholder="Search">
</div>
<button type="submit" class="btn btn-default btn-sm">Submit</button>
</form>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav pull-right">
<li>Site Tool Link</li>
<li>Site Tool Link</li>
<li>Site Tool Link</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<!-- Primary Navbar -->
<div class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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 class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown active">
Menu #1 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link #1</li>
<li>Link #2</li>
</ul>
</li>
<li class="dropdown">
Menu #2 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link #1</li>
<li>Link #2</li>
</ul>
</li>
<li class="dropdown">
Menu #3 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link #1</li>
<li>Link #2</li>
</ul>
</li>
<li class="dropdown">
Menu #4 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link #1</li>
<li>Link #2</li>
</ul>
</li>
<li class="dropdown">
Menu #5 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link #1</li>
<li>Link #2</li>
</ul>
</li>
<li class="dropdown">
Menu #6 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Link #1</li>
<li>Link #2</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
CSS:
.navbar {
border-radius: 0px;
}
.siteTools {
margin-bottom: 0px;
background-color:#cdcdcd;
border:none;
}
I know the other answer has already been marked correct, but I don't think that specifying a height is the correct way to fix this.
Even if you override the default min-height and set it to 0, the menu is still tall, and that's because of the padding and margins of the elements inside that navbar. By explicitly setting height: 35px you'll be cutting of the content inside the navbar at 35px. This looks bad and is not great for anyone wanting bigger font sizes etc.
I think you should adjust the elements inside the navbar instead like this:
.siteTools {
min-height:0;
margin-bottom: 0px;
background-color:#cdcdcd;
border:none;
}
.siteTools .nav > li > a {
padding: 7px 10px;
font-size: 12px;
}
.siteTools form[role="search"] {
margin: 4px 0;
}
.siteTools form[role="search"] input {
padding: 3px 5px;
height: 25px;
}
.siteTools form[role="search"] button[type="submit"] {
padding: 3px 5px;
height: 25px;
}
Working demo here.
This should help you. min-height is blocking shrinking your element bellow its value.
.navbar {
border-radius: 0px;
}
div.siteTools.navbar {
height:35px;
min-height:35px;
margin-bottom: 0px;
background-color:#cdcdcd;
border:none;
}

Bootstrap 3 Fixed Nav - Hide/Resize Logo

Using the latest version Bootstrap, I am wanting to replace the branding area text with a logo. On my desktop, it looks perfect, on my iPhone, the logo appears under the small collapse menu, whereas it should be beside it (to the left of it). If I make the logo smaller, it works fine on the iPhone, but the small logo is too small for the desktop site. I thought by adding the img-responsive class to the logo, it would shrink accordingly, but that fails. If you want to replicate this, the logo is 276px wide 40px high.
Everything appears fine on the iPhone in horizontal orientation (it is strictly a problem when viewing in vertical, which is naturally the way most people hold their phone).
Here is the related code (you will notice near the bottom, there is a purchase button, this automatically gets hidden on the iPhone, which would suffice for the logo if there is no other option). Mind, the ultimate solution would be to have the logo shrink based on screen size.
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php"><img class="img-responsive" src="img/logo.png" alt=""></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
Application <b class="caret"></b>
<ul class="dropdown-menu">
<li>Features</li>
<li>Screenshots</li>
<li>Demos</li>
<li class="divider"></li>
<li>Purchase</li>
<li>Licensing Model</li>
</ul>
</li>
<li class="dropdown">
Documentation <b class="caret"></b>
<ul class="dropdown-menu">
<li>Version Info</li>
<li>System Requirements</li>
<li class="divider"></li>
<li>Installation Guide</li>
<li>Integration Guide</li>
<li>Frontdesk Manual</li>
</ul>
</li>
<li class="dropdown">
Support <b class="caret"></b>
<ul class="dropdown-menu">
<li>Knowledgebase</li>
<li>Submit Ticket</li>
<li>View Ticket Status</li>
<li class="divider"></li>
<li>Installation Service</li>
<li>Development Services</li>
</ul>
</li>
<li class="dropdown">
Contact <b class="caret"></b>
<ul class="dropdown-menu">
<li>Presales Questions</li>
<li>Contact Us</li>
</ul>
</li>
<li class="dropdown">
Legal <b class="caret"></b>
<ul class="dropdown-menu">
<li>Privacy Policy</li>
<li>Terms of Use</li>
<li>Site Security</li>
<li class="divider"></li>
<li>Money Back Guarantee</li>
</ul>
</li>
</ul>
<button type="button" class="btn btn-success" style="margin-top: 8px; margin-left: 30px;">Purchase</button>
</div>
<!--/.nav-collapse -->
This fixes the I-phone issue with the brand logo appearing under the collapsed menu icon. you might have to play with the width a bit depending on your setup:
#media (max-width: 500px) {
.navbar-brand{
width:60%;
}
}
Put your image as a background in css with background-size:cover.

Adding a search bar into main menu on Bootstrap

I'm making a website using Twitter's Bootstrap and everything is almost set but I can't figure how to position a search bar into the main menu
Here is the website online
http://testings.coffeecup.com/index1.html
Each time I put it anywhere on the container it screws up either.
EDIT:
I managed to add it:
http://gyazo.com/e76b7cfa8e25b9ef2913d588b28ea894
But I still can't position it on the right.
The css I'm using
.navbar-search {
position: relative;
}
.navbar-search .search-query {
float:right;
}
.navbar-search .icon-search {
position: absolute;
top: 7px;
background-image: url("");
}
Right after the <div class="navbar-inner"> include the search bar <input> with whichever attributes you need .. after just float it to the right and adjust the margins so its centered vertically in the nav-bar.
You have to add the search-bar inside <div class="navbar-inner"> and after <div class="nav-collapse collapse">.
The code for the search bar:
<input id="search" class="span3" type="search" name="search" placeholder="Search">
You can use the pull-right class
i used it in the container
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Title</a>
<div class="nav-collapse collapse navbar-responsive-collapse">
<ul class="nav">
<li class="active">Home</li>
<li>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 class="nav-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-search pull-right" action="">
<input type="text" class="search-query span2" placeholder="Search">
</form>
<ul class="nav pull-right">
<li>Link</li>
<li class="divider-vertical"></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><!-- /.nav-collapse -->
</div>
</div>
REsult :

Resources