I have the following Bootstrap navigation set up. I want to reduce the space between each li in the ul under the "Coverage" dropdown-toggle. What setting do I use to do this? As a side note, when I set float: left on the ul li a, the space is reduced, but I don't need float to do this. Why does it reduce the space though?
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand mycontent5" href="/?goHome=true"><span class="glyphicon glyphicon-home"></span></a>
<button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
<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 navbar-left">
<ul class="nav navbar-nav">
<li>Analysts</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Coverage<span class="caret"></span></a>
<ul class="dropdown-menu" id="mynavlist">
<li>All Coverage</li>
<li>Coverage Assignments</li>
<li>Portfolio Coverage</li>
<li>Portfolio Snapshot</li>
<li>Writeup Sections</li>
</ul>
</li>
<li>Funds</li>
<li>Intraday Orders</li>
<li>Reports</li>
</ul>
</div>
</nav>
EDIT: I changed my ul to have an id of "mynavlist", and added the following CSS:
#mynavlist li a {
padding-top: 0px !important;
padding-bottom: 0px !important;
margin-top: 0px !important;
margin-bottom: 0px !important;
}
This results in the following: I want to get rid of all white space above and below each item. Increasing the px sizes changes my list as expected, but how can I get rid of the extra space?
You have to reduce the top and bottom padding of each item. Try below css
.navbar-default .dropdown-menu>li>a {
padding: 0 20px;
}
/*For responsive*/
#media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu>li>a {
padding: 0 20px;
}
}
.navbar-default .dropdown-menu>li>a {
padding: 0 20px;
}
/*For responsive*/
#media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu>li>a {
padding: 0 20px;
}
}
<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" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand mycontent5" href="/?goHome=true"><span class="glyphicon glyphicon-home"></span></a>
<button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
<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 navbar-left">
<ul class="nav navbar-nav">
<li>Analysts</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Coverage<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>All Coverage</li>
<li>Coverage Assignments</li>
<li>Portfolio Coverage</li>
<li>Portfolio Snapshot</li>
<li>Writeup Sections</li>
</ul>
</li>
<li>Funds</li>
<li>Intraday Orders</li>
<li>Reports</li>
</ul>
</div>
</nav>
If you use your browsers Console or Inspector you can view each HTML element and any CSS that is being applied to that element. In the case of Bootstrap's Navbar component you will find the following:
.navbar-nav > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
Changing 15px to some other value will result in your desired output, though you should note that Bootstrap modifies the top and bottom padding for this element based on certain media breakpoints: you will need to account for this in your customizations.
Related
I have the following HTML for a bootstrap navbar.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 33px;
padding-bottom: 20px;
}
.body {
font-size: 16px;
border-spacing: 2px;
border-collapse: separate;
text-align: center;
}
.body a {
text-decoration: underline;
}
.navbar-fixed-top {
background-color: #5b5b5b;
min-height: 33px;
border-style: none;
}
.navbar-toggle {
margin-top: 2px;
margin-bottom: 2px;
padding-top: 7px;
padding-bottom: 7px;
}
.navbar-nav>li>a {
line-height: 3px;
padding-top: 16px;
padding-bottom: 14px;
}
div.navbar-header>img {
height: 30px;
margin-top: 2px;
}
.nav>li>a {
font-size: medium;
font-family: "Helvetica Bold", sans-serif;
/*font-weight: bold;*/
text-transform: uppercase;
}
.navbar-inverse .navbar-nav>li>a {
color: #f0eed0;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: #f8dc54;
}
.nav li {
display: inline;
}
#vugraph-menu.inprogress>a {
color: black;
background-color: #ecbe23;
}
#vugraph-menu.inprogress>a:hover,
#vugraph-menu.inprogress.open>a:not(:hover) {
color: white;
}
</style>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<img src="http://www.bridgebase.com/images/bbo_red.png">
<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>
<div id="navbar" class="nav navbar-collapse collapse">
<div class="container">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Vugraph <span id="vugraph-count" class="badge badge-notify"></span></a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">Watch</li>
<li class="dropdown-item">Schedule</li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a></li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a></li>
<li class="nav-item"><a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a></li>
</ul>
</div>
</div>
</div>
</nav>
With no badge this looks like:
I have JavaScript that dynamically fills in the #vugraph-count badge. When it has contents, the height of the navbar increases by more than 15 pixels. The HTML becomes:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 33px;
padding-bottom: 20px;
}
.body {
font-size: 16px;
border-spacing: 2px;
border-collapse: separate;
text-align: center;
}
.body a {
text-decoration: underline;
}
.navbar-fixed-top {
background-color: #5b5b5b;
min-height: 33px;
border-style: none;
}
.navbar-toggle {
margin-top: 2px;
margin-bottom: 2px;
padding-top: 7px;
padding-bottom: 7px;
}
.navbar-nav>li>a {
line-height: 3px;
padding-top: 16px;
padding-bottom: 14px;
}
div.navbar-header>img {
height: 30px;
margin-top: 2px;
}
.nav>li>a {
font-size: medium;
font-family: "Helvetica Bold", sans-serif;
/*font-weight: bold;*/
text-transform: uppercase;
}
.navbar-inverse .navbar-nav>li>a {
color: #f0eed0;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: #f8dc54;
}
.nav li {
display: inline;
}
#vugraph-menu.inprogress>a {
color: black;
background-color: #ecbe23;
}
#vugraph-menu.inprogress>a:hover,
#vugraph-menu.inprogress.open>a:not(:hover) {
color: white;
}
</style>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<img src="http://www.bridgebase.com/images/bbo_red.png">
<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>
<div id="navbar" class="nav navbar-collapse collapse">
<div class="container">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Vugraph <span id="vugraph-count" class="badge badge-notify">1</span></a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">Watch</li>
<li class="dropdown-item">Schedule</li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a></li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a></li>
<li class="nav-item"><a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a></li>
</ul>
</div>
</div>
</div>
</nav>
and the rendered navbar looks like:
(I had to put our custom CSS inline in the HTML box of the snippet, because otherwise bootstrap.min.css was taking priority over the custom styles.) You'll need to use the "Full page" option of the stack snippets to get the non-collapsed navbar.
The problem appears to be related to the .navbar-nav>li>a style line-height: 3px. When I remove that, the navbar is always too tall. This is being used to reduce the navbar height to match the logo on the left. For some reason, when the badge is added, it's overriding this (although it's not striked out in the DOM inspector).
The badge is not causing the problem, you can check next example with two navbars (one with badge filled with a number, other without it) where both have similar height (like Chris Bar already noted). So:
1) It could be a problem with some of your custom CSS, in this case, I recommend to use the inspector tool to check what style is added to your badge or navbar.
2) Another thing you could do is check if you have a well structured navbar as explained on Bootstrap Navbar.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<!-- Brand and collapse button -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar1">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Navbar 1</a>
</div>
<div id="navbar1" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Vugraph
<span id="vugraph-count" class="no-padding badge badge-notify">99</span>
</a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">
Watch
</li>
<li class="dropdown-item">
Schedule
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a>
</li>
</ul>
</div>
</div>
</nav>
<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<!-- Brand and collapse button -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar2">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Navbar 2</a>
</div>
<div id="navbar2" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Vugraph
<span id="vugraph-count" class="no-padding badge badge-notify"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">
Watch
</li>
<li class="dropdown-item">
Schedule
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a>
</li>
<li class="nav-item">
<a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a>
</li>
</ul>
</div>
</div>
</nav>
Finally, I don't believe that updating to Bootstrap 4 will help here, indeed, you will have to port your entire site to the new version because there are thing that changed from version 3 to 4 (Read more here).
Update
After the question was updated with the custom style applied on the elements, a possible solution is to add next style to the badge:
{line-height: 0; display: inline;}
Example:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
/* Move down content because we have a fixed navbar that is 50px tall */
#vugraph-count {
line-height: 0;
display: inline;
}
body {
padding-top: 33px;
padding-bottom: 20px;
}
.body {
font-size: 16px;
border-spacing: 2px;
border-collapse: separate;
text-align: center;
}
.body a {
text-decoration: underline;
}
.navbar-fixed-top {
background-color: #5b5b5b;
min-height: 33px;
border-style: none;
}
.navbar-toggle {
margin-top: 2px;
margin-bottom: 2px;
padding-top: 7px;
padding-bottom: 7px;
}
.navbar-nav>li>a {
line-height: 3px;
padding-top: 16px;
padding-bottom: 14px;
}
div.navbar-header>img {
height: 30px;
margin-top: 2px;
}
.nav>li>a {
font-size: medium;
font-family: "Helvetica Bold", sans-serif;
/*font-weight: bold;*/
text-transform: uppercase;
}
.navbar-inverse .navbar-nav>li>a {
color: #f0eed0;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: #f8dc54;
}
.nav li {
display: inline;
}
#vugraph-menu.inprogress>a {
color: black;
background-color: #ecbe23;
}
#vugraph-menu.inprogress>a:hover,
#vugraph-menu.inprogress.open>a:not(:hover) {
color: white;
}
</style>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<img src="http://www.bridgebase.com/images/bbo_red.png">
<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>
<div id="navbar" class="nav navbar-collapse collapse">
<div class="container">
<ul class="nav navbar-nav">
<li id="vugraph-menu" class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Vugraph <span id="vugraph-count" class="badge badge-notify">1</span></a>
<ul class="dropdown-menu" aria-labelledby="navbar-vugraph-menu-link">
<li class="dropdown-item">Watch</li>
<li class="dropdown-item">Schedule</li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/myhands/index.php" target="_blank">Hand Records</a></li>
<li class="nav-item"><a class="nav-link" href="//www.bridgebase.com/points/index.php" target="_blank">Masterpoints</a></li>
<li class="nav-item"><a class="nav-link" href="https://www.bridgebase.com/purchase/pay.php" target="_blank">BB$</a></li>
</ul>
</div>
</div>
</div>
</nav>
Check out this quick test that measures the height of the nav items with and without a badge. There is a small difference, but not much. only 0.04 pixels.
You might have other CSS that is interfering and makes the badge a bit taller. If the padding or line-height of the .badge is made smaller, then the two nav items have the same height. See the commented out CSS code, uncommenting this fixes the issue in the demo here
document.querySelectorAll('.nav-item').forEach((el) => {
console.log(el.innerText + ' Height: ' + el.getBoundingClientRect().height + 'px')
});
.nav-item {
border: 1px solid red;
}
.nav-item .badge {
/*line-height: 90%;*/
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" />
<div id="navbar" class="nav navbar-collapse">
<div class="container">
<ul class="nav navbar-nav">
<li class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">No Badge</a>
</li>
<li class="nav-item dropdown" title="No tables in play">
<a id="navbar-vugraph-menu-link" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Has Badge <span id="vugraph-count" class="badge badge-notify">1</span></a>
</li>
</ul>
</div>
</div>
I have a question about positioning my links on navbar collapse. I want the left sided links to be displayed on one line in the collapsed menu, and the right sided links to be displayed on the next line.
Right now I can get all the links displayed on the same line using "display: inline-flex" in my css, but I don't know how to separate them.
Here is my current HTML and CSS:
<div class="container">
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-left">
<li>Link 1</li>
<li>Link 2</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link 3</li>
<li>Link 4</li>
<li>Link 5</li>
</ul>
</nav>
</div>
.navbar-right {
float: right;
margin-right: -15px;
}
.collapse > .navbar-left {
display: inline-flex;
}
.collapse > .navbar-right {
display: inline-flex;
}
.navbar .navbar-nav {
float: none;
vertical-align: top;
text-align: center;
}
And a link to my jsFiddle: https://jsfiddle.net/wdeg6rko/
Any help is much appreciated!
Use a media query to contain the rules so they only apply under 768px and use inline-block against the li items and set the navbar-navs width to 100% while removing any margin so they are actually centered.
Working example Snippet.
#media (max-width: 767px) {
.navbar.navbar-default .navbar-nav {
width: 100%;
text-align: center;
margin: 0;
}
.navbar.navbar-default .navbar-right > li,
.navbar.navbar-default .navbar-left > li {
display: inline-block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-left">
<li>Link 1
</li>
<li>Link 2
</li>
<li>Link 3
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link 3
</li>
<li>Link 4
</li>
<li>Link 5
</li>
</ul>
</div>
</nav>
</div>
As there is float: left !important; is added to .navbar-left. To override it use following css:
.nav.navbar-nav.navbar-left {
float: none !important;
}
Fiddle
I'm attempting to preserve the position of two menu element (Home icon and Foo) that render as desired on large devices:
But are displayed as rows on a mobile device (obscuring content):
Is there a way to force these two menu items to display to the right of the Brand menu and on the same 'row'?
Sample: http://www.bootply.com/Fjq7ZXSDXc#
You can create a separate div inside the navbar-header: See example Snippet.
.navbar-header .nav-icons {
padding-top: 12px;
position: absolute;
display: inline-block;
top: 0;
}
.navbar-header .nav-icons span {
padding-left: 5px;
padding-right: 5px;
font-size: 20px
}
.navbar-header .nav-icons a {
color: #fff;
text-decoration: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top custom-navbar" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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" rel="home" href="#" title="Help"> Brand</a>
<div class="nav-icons">
<a href="#"> <span class="glyphicon glyphicon-home"></span>
</a>
<a href="#"> <span> Foo</span>
</a>
</div>
</div>
<div class="navbar-collapse collapse" id="navbar-collapse-1">
<!-- Non-collapsing right-side icons -->
<ul class="nav navbar-nav navbar-right">
<li class="active">Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="text-center">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.
<br>All you get is this text and a mostly barebones HTML document.</p>
</div>
</div>
<!-- /.container -->
Try to add this in your .css
.nav-collapse .nav > li {
display: inline-block;
}
I'm going crazy styling predifined bootstrap classes. First of all, I've got problems to access the icon-bar class, it doesn't get styled. Second of all, when shrinking the browser, the navigation bar collapses at some point but before that, it's rearranged in two rows (BRAND continues in its place but the menu gets to a second row). I want it to get collapsed when there's no space for both the menu and the brand to coexist in the same row.
How can I solve this?
HTML
<header id="header-bar" 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="#menu">
<span class="icon-bar"></span> <!-- Not Styled -->
<span class="icon-bar"></span> <!-- Not Styled -->
<span class="icon-bar"></span> <!-- Not Styled -->
</button>
<a class="navbar-brand" href="#">BRAND</a> <!-- STYLED -->
</div>
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav">
<li><a class="options" href="#">AAAAAAAAA</a></li>
<li><a class="options" href="#">BBBBBBBBB</a></li>
<li><a class="options" href="#">CCCCCCCCC</a></li>
<li><a class="options" href="#">DDDDDDDDD</a></li>
<li><a class="options" href="#">EEEEEEEEE</a></li>
<li><a class="options" href="#">FFFFFFFFF</a></li>
<li><a class="options" href="#">GGGGGGGGG</a></li>
<li><a class="options" href="#">HHHHHHHHH</a></li>
</ul>
</div>
</div> <!-- Container -->
</header>
CSS
$blue-logo: #4775FF;
header .container-fluid {
background-color: $blue-logo;
border-radius: 5px;
margin-top: 5px;
margin-left: 5px;
margin-right: 5px;
max-height: 50px;
.navbar-header {
a { color: white;}
.navbar-toggle .icon-bar { color: red;}
}
#menu ul li a{
color: gainsboro;
}
}
So I have a navbar-fixed-top that's set to collapse at 992px, most mobile screens wont collapse at anything lower than that anymore. Well, from what I can tell anyway. The problem is that when I try increase the navbar height at the lower screen width, I cant vertically center anything on the navbar - being the placeholder for the logo to come or the dropdown button. I'm also struggling to increase the size of the dropdown button no matter what I try. Finally as soon as I increase the height of the navbar, when I click the dropdown menu, the background image disappears yet it works fine with the default height. I'm really hoping someone knows a trick or two as it seems lots of people are struggling with navbar-fixed-top.
Here's the html setup:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Logo</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsed-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>
<div class="collapse navbar-collapse" id="collapsed-navbar">
<ul class="nav navbar-nav">
<li><a ng-href="#link">Link 1</a></li>
<li><a ng-href="#link">Link 2</a></li>
<li><a ng-href="#link">Link 3</a></li>
<li><a ng-href="#link">Link 4</a></li>
<li class="divider"></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><img class="img-circle nav-profile-image" src="images/default_pic.png" /></li>
<li><a ng-href="#link">Profile</a></li>
<li>Logout</li>
</ul>
</div>
</div>
</nav>
And here's the CSS so far:
#media (max-width: 992px) {
.nav-profile-image {
display: none;
}
.navbar {
height: 80px;
font-size: 24px;
}
}
#media (min-width: 992px) {
.nav-profile-image {
height: 40px;
margin-top: 5px;
}
}
.navbar {
background-image: url('../images/noise-background.jpg');
background-color: #F8F8F8;
}
.navbar-default .navbar-nav > li > a:hover {
color: #555;
background-color: #E7E7E7;
opacity: 0.6;
}
.navbar-default .navbar-nav > .active > a:hover {
color: #555;
background-color: #E7E7E7;
opacity: 1;
}
Thanks in advance!