How do I align elements in bootstrap's nav bar? - html

I'm working with some custom bootstrap css for a collapsible navbar (https://github.com/IronSummitMedia/startbootstrap/tree/master/templates/grayscale). I tried adding a search bar up top, and I want the search bar to be in line with the icon, with the links underneath: 174.37.193.115/chrome/
<nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="#page-top">
<i class="fa fa-bolt fa-lg"></i>
</a>
<div class="input-group col-lg-6 col-lg-offset-0">
<input type="text" class="form-control" placeholder="Look for people, groups, and anything">
<span class="input-group-addon"><i class="fa fa-search"></i></span>
</div>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-main-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
</li>
<li>
News
</li>
<li>
Profile
</li>
<li class="dropdown">
Something
<ul class="dropdown-menu">
<li>One
</li>
<li>Two
</li>
<li>Three
</li>
</ul>
</li>
<li>
Bamn
</li>
<li>
Pewpew
</li>
<li>
Vroom
</li>
<li>
Wheeeew
</li>
<li>
Bzzzt
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Unfortunately, I can't seem to get the search bar to go into the right place, and something really funky seems to be going on. In general, I'm also confused as to which elements can stack in line with each other (I can't seem to force it via col).
Any help in getting the search bar in line with the bolt, and links underneath would be appreciated! An explanation of how elements stack in line would be an added bonus!

To get the nav links under the above stuff:
.nav>li>a {
padding: 10px 30px 10px 0;
}
To make hoverstates look nicer, perhaps this is better:
.nav>li>a {
padding: 10px 0;
margin-right: 30px;
}
Or, if you just want to compensate for the padding offset, you can move the whole navbar to the left:
.navbar-nav {
margin-left: -15px;
}
To get the search bar inline with the logo:
.col-lg-6 {
margin-top: 12px;
}
Just add these rules to your own css file that you will call after the bootstrap ones. You might also to similar things for other responsive variations (or switch to percents).

Related

Fill Remaining Width of parent

I have a navigation menu, with a collapsible list of child pages. Except the dropdown element needs to have an accessible page on the same line as well. This is what I have so far.
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-lg-2">
<div class="navbar navbar-default navbar-fixed-side">
<ul class="nav" id="side-menu-0">
<li id="menu-template" class="nav">
<i class="fa fa-dashboard fa-fw"></i>Dashboard
</li>
<li id="menu-template-top" class="nav" role="menu">
Google
<span class="caret"></span>
<ul id="menu-template-top-sub" class="collapse nav nav-second-level">
<li class="nav">
Flot Charts
</li>
<li class="nav">
Morris.js Charts
</li>
</ul>
<!-- /.nav-second-level -->
</li>
</ul>
</div>
</div>
Here is the working fiddle, so you can see what I am trying to do. I want the Link for "Google" to stretch across to the right, like the "Dashboard" link can do. Working Fiddle
A simple fix for this is to do this:
Google
You could of course externalize this to a stylesheet if you wish.
The 40px in the calc(100% - 40px) is the width of your dropdown caret.
This makes it stretch all the way to the dropdown-expansion button.
Add display block to your <a> tag, instead of display inline-block. Block elements will span the entire width.

Increasing the height of the Bootstrap Collapsed "mobile" navigation menu?

I am struggling to get the mobile collapsed drop down nav to increase in height. Currently it is stuck at about 340px and I need it to expand to fit the menu items being contained within the collapsed nav. I have searched tirelessly on Google and here to find an answer but none of them seem to make an impact, even when I use !important.
Here's a screenshot of what I am talking about to avoid any confusion. The blue bordered area that I added to the screenshot is what I am talking about. This seems to be set to a static height and I need it to extend about another 50px-100px for this particular application. I did not show code here because I am hoping to just see the "best way" to change the default height for my future reference.
Thanks for the help!
EDIT: I did not submit code because right now it's just the default bootstrap nav code so I didn't think I needed to reference it.
Here's the code, I am just using a simple generic startbootstrap.com template here.
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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 page-scroll" href="#page-top">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
I have no custom CSS yet as this is the first thing I am trying to change and don't know where in the CSS the dropdown nav should be edited.
Without seeing the code it is difficult to say what is impacting the height. If you add more <li>'s to the menu, does it expand?
If not, there could be a static height or max-height css property applied to the .dropdown-menu
Editing for improvement:
It looks like either of these elements;
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
has a height or max-height and overflow:auto property.
Inspect these elements in chrome to see if this is the case. Then, set height:auto; and/or adjust the max-height property to allow for increased height for that element.
You can set these in your custom CSS file and they will override Bootstrap's style. Just ensure that your CSS file is loaded after the Bootstrap CSS file.
If you can post a link I can look at it and provide the exact code needed to make the changes.
I had the same problem with my mobile collapsed drop-down navigation displaying a scrollbar rather than expanding to show all the navigation links. My solution was to hide the scrollbar then add pixels to the bottom of my data-target div.
You should be able to hide the scrollbar using:
.navbar-collapse.in {
overflow: hidden;
}
Then you can add the extra pixels needed at the bottom by adding padding to the data-target div when sized for mobile devices:
#media (max-width: 768px) {
.navbar-ex1-collapse {
padding-bottom: 50px;
}
}

twitter bootstrap - moving objects to navbar when collapsed bootstrap 3

I got a topnavbar which disappears when the website gets loaded on a mobile device but I would like the content that is on that topnavbar to appear on the collapsed main navigation.
TOPNAVBAR
COLLAPSED NAVIGATION
How would I be able to achieve this or is this even possible or do I have to create a class specially for the collapsed menu?
Thank you in advance
What I sometimes do is the following:
1) You create your top-menu container for big devices
2) You create the same menu in your collapse container for small devices
3) Use css and #media to switch between to 2 lists
<header>
<div class="container">
<!-- Top menu for not mobile devices -->
<div id="top-menu" class="clearfix">
<ul class="nav navbar-nav">
<li>
<a href="#">
TopItem1
</a>
</li>
<li>
<a href="#">
TopItem2
</a>
</li>
</ul>
</div>
<!-- Navigation bar -->
<div class="navbar navbar-default">
<div class="navbar-header">
<!-- Toggle menu -->
<button class="navbar-toggle" data-target=".navbar-collapse" data-toggle="collapse" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Logo -->
<a class="navbar-brand" href="/nl/">
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#">
Item1
</a>
</li>
<li>
<a href="#">
Item2
</a>
</li>
<li>
<a href="#">
Item2
</a>
</li>
</ul>
<!-- Same top menu links for small devices -->
<ul class="nav navbar-nav navbar-right" id="top-responsive">
<li>
<a href="#">
TopItem1
</a>
</li>
<li>
<a href="#">
TopItem2
</a>
</li>
</ul>
</div>
</div>
</div>
</header>
CSS:
Standard css style:
#top-responsive {
display: none;
}
#top-menu {
display: block;
}
With #media for small devices:
#media (max-width: 767px)
{
#top-responsive {
display: block;
}
#top-menu {
display: none;
}
}
Jsfiddle: http://jsfiddle.net/VDesign/qyosv002/
EDIT:
Like Vicente said, Bootstrap provides utility classes that does the same thing I do.
You can find the intell about it on the website of Bootstrap: http://getbootstrap.com/css/#responsive-utilities

How to float div up?

I have a menu and a submenu in different divs. There is a space between them. How can I make them look like a one whole menu? I used bootstrap navbar for main menu and simple nav for submenu. I'm very newbie in css. this is what I have:
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="#">Website Logo</a>
<ul class="nav">
<li class="active">DashBoard</li>
<li>Docs</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">Account<b class="caret"></b></a>
<ul class="dropdown-menu" style="width: 250px;">
<li>Dashboard</li>
<li>LogOut</li>
</ul>
</li>
</ul>
</div>
</div>
<div>
<ul class="nav nav-pills">
<li class="active">
Stats
</li>
<li>Api Calls</li>
<li>Settings</li>
</ul>
</div>
jsfiddle
I just want to remove the space between them.
And one more little question:
how can I get rid of a little caret between button and it's dropdown? (white triangle between Account nav item and it's dropdown)
Your first question can be answered by removing the default margin-bottom for the class navbar:
.navbar {
margin-bottom:0
}
Now, for your second question. There is a triangle created using borders on your dropdown-menu. You can disable this with this css:
.navbar .nav > li > .dropdown-menu:after {
border:none;
}
Add the following CSS to remove the margins:
.navbar{
margin:0px;
}
JS Fiddle: http://jsfiddle.net/eszf7/3/

Bootstrap navbar height changed on inserting brand image

I am new to HTML and CSS and have started coding in the last 4 days. I found bootstrap very useful to get things moving quickly.
Here is my attempt at getting a Navbar with transparency and fixed to the top.
http://jsfiddle.net/revanur/mf5wc/4/
<!-- Top-Navigation-Bar -->
<div class="row-fluid">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner" id="topbar">
<div class="container"> <img class = "brand" src="http://placehold.it/269x50" alt="SparkCharger" />
<button id="topbtn" 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>
<div class="nav-collapse">
<ul class="nav pull-right">
<li class="active">
<form class="navbar-search brand">
<input type="text" class="search-query" placeholder="Search">
</form>
</li>
<li> <h5> Discover </h5>
</li>
<li> <h5> Blog </h5>
</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#"><h5>Start <span class="caret"></span></h5></a>
<ul class="dropdown-menu">
<li> <h6> Login </h6>
</li>
<li> <h6> Signup </h6>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- /Top-Navigation-Bar -->
However, the height of the navbar seems to change based on brand image size. I have no problem with that but I notice significant spacing between the image and the navbar top and bottom. How do I change this. Also, is it possible to fix the navbar size so that the navbar does not have a mind of its own.
There are a few things affecting the height of the navbar:
div class="navbar-inner" (5px padding)
img class="brand" (10px padding)
the size of the image
You can remove the padding by:
img.brand {
padding: 0;
}
And/Or you can specify the height of the navbar:
div.navbar-inner {
height: 10px;
}
Use something like this:
.brand {height: 25px;}
Demo: Fiddle