I am trying to decrease the height of the Bootstrap 3.1.1's navbar without using the less version of it. I have tried several ways of doing this by reading around on different sites, and none of them are decreasing the CSS's .navbar height.
I have managed to fix the padding on the .navbar-nav > li > a.
My HTML:
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">QuadCMS</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Help</li>
</ul>
</div>
</div>
</div>
My CSS which overrides the Bootstrap to try to fix the navbar.
.navbar {
height: 25px !important;
}
.navbar-nav > li > a {
padding-top: 5px !important;
padding-bottom: 5px !important;
}
My main issue is with the actual height of the navbar, not the padding now. The padding of the navigation links are fixed and working at the small size. I have also tried changing the .navbar to .navbar-nav, and .navbar-fixed-top respectfully and nothing has worked yet.
Do I need to call a different CSS Class then the ones I have tried, or do I need to call two of the ones I have already tried to get the effect needed?
Here is the default .navbar styling:
.navbar {
position: relative;
min-height: 50px;
margin-bottom: 20px;
border: 1px solid transparent;
}
You need to overwrite the min-height property. You can use the value inherit.
Example Here
.navbar {
height: 30px;
min-height: inherit;
}
.navbar-nav > li > a {
padding-top: 5px;
padding-bottom: 5px;
}
.navbar-brand {
padding:5px 0 0 0;
}
Related
The way I have my navbar set up right now is when I am scrolled to the top, the navbar background is transparent, and as soon as I start scrolling down, the navbar background appears as black. The only problem I am having right now is when I am on mobile size and I am scrolled to the top, when I click the navbar toggle dropdown button, the background on the drop down menu is transparents since I am scrolled all the way up, but I'd like to find a way to have the black background appear when the dropdown menu is active when scrolled all the way to the top of the browser.
HTML
<nav class="navbar navbar-default top-of-page">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<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" href="#"><img src='/CMS_Static/Uploads/313864614C6F6F/fv-logo-3.gif' align="left"/></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul id="navLinks" class="nav navbar-nav">
<li>Home</li>
<li>Services</li>
<li>Stock Photography/ Footage</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
Java Script
<script> $(window).on("scroll", function() {
var scrollPos = $(window).scrollTop();
if (scrollPos <= 0) {
$('.navbar-default').addClass('top-of-page');
} else {
$('.navbar-default').removeClass('top-of-page');
}
});
</script>
CSS
.top-of-page {
background-color: transparent;
}
.navbar-default {
background-color: black;
background: rgba(0,0,0,.85);
min-height: 90px;
position: fixed;
border-radius: 5px;
border: none;
width: 100%;
z-index: 1;
}
#navLinks {
padding-left: 20px;
}
#navLinks li {
padding-top: 20px;
padding-right: 10px;
}
#navLinks li a {
color: white;
font-size: 1.1em;
font-weight: 700;
}
#navLinks li a:hover {
color: #a6b1c4;
}
.navbar-brand img {
height: 35px;
}
Write media query. when device width is less than something say 700px for phone give background color to ... top-of-page class.
code ...
#media only screen and (max-width: 500px) {
.top-of-page{
background-color: #000;
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
So I've designed a mock website layout for a made up company so I can test my skills at Twitter's Bootstrap 3 but I'm having problems relaying what I've designed on photoshop to code.
I'm trying to get the whole navbar content centered, with links at either side of the brand logo. I've checked online, google, stackoverflow and more, however I can't seem to get it anywhere near what I've designed! I'm having a hard time getting my head around it. It seems like it should be simple, and I've just overthought it's complexity! The links need to be center to the image, but also center in the navbar itself. The layout as such:
[link] [link] [LOGO] [link] [link]
Here's an image of the mentioned design:
To center the floated navbar-nav you can use relative position and negative left, right values on the navbar-nav itself and on the list items or child elements.
To make sure that the logo is always centered you may think about not using a nav-justified but a regular navbar-nav with a fixed value for left and right padding on the anchor tags, but with individual values for different screens.
To get the vertical alignment working just add the appropriate line-height to the anchor tags.
I have decided to hide the actual navbar-brand and only show it on sx breakpoint.
For the centered logo it is the other way around, so we do not have the logo inside the collapsed nav. Just look at the example and i am sure you will get the idea.
Here is the example.
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}
.navbar-brand {
padding: 0 15px;
height: 96px;
}
#media (min-width: 768px) {
.navbar-nav {
position: relative;
right: -50%;
}
.navbar-nav > li {
position: relative;
left: -50%;
}
.navbar-nav > li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}
#media (min-width: 992px) {
.navbar-nav > li a {
padding: 0 48px;
}
}
#media (min-width: 1200px) {
.navbar-nav > li a {
padding: 0 68px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-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 hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Who We Are</li>
<li>Our Food</li>
<li class="hidden-xs"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></li>
<li>Book a Table</li>
<li>Promotions</li>
</ul>
</div>
</div>
</nav>
You can also try flexbox display. In order to implement it, you will have to:
add the display: flex property to the parent element of the elements that you need to align (in this case: on the <ul> element in the navbar, which contains the list of navigation links and the brand image)
set margin: auto for the elements you need to align (in this case: on the <li> elements)
Optional: if you don't want your elements to show up in a row (default bahavior), adjust the value of the flex-direction property. E.g. if you want to have the elements listed vertically, add flex-direction: column; to the <ul> element.
Here is a sample code, with two different image-placements: on-top of the list for mobile devices and in the middle of the row for small devices and above.
HTML:
...
<nav class="container">
<div class="row visible-xs text-center">
<div class="col-xs-12">
<img src="images/logo.png" alt="BLUE|BERY"/>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<ul class="text-center">
<li>Who We Are</li>
<li>Our Food</li>
<li class="hidden-xs"><img src="images/logo.png" alt="BLUE|BERY"/></li>
<li>Book a Table</li>
<li>Promotions</li>
</ul>
</div>
</div>
</nav>
...
CSS:
body {background-color: #333333;}
nav {background-color: #000000;}
nav ul {
display: flex;
list-style-type: none;
padding-left: 0; //in order to eliminate Bootstrap's built-in 40px padding
}
nav ul > li {margin: auto;} //N.B. don't alter the margin property, if you want some further adjustments, use padding!
nav ul > li > a:link, :visited, :hover, :active {
color: #ffffff;
text-decoration:none;
}
#media all and (max-width:767px) {
nav a > img {margin: 20px auto;}
nav ul {flex-direction: column;} //only if you want to change the default direction
}
So I've made a typical Bootstrap navbar and it works well on Desktop sizes. By default, when I added my logo wrapped with the navbar-brand class as in their documentation example, the logo overhangs off the navbar. I solved this problem by adding padding to the links themselves. This works fine until I resize the browser to act like a mobile device. When it collapses, the navbar's height decreases to fit the toggle switch and the logo again overhangs. How to I fix this? Did I go about making the height of the navbar the right way by adding padding? Or should I make it a fixed height by specifically assigning it?
The logo is 55px tall by 128px wide.
Here's my HTML:
<nav id="LC-navbar" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div id="LC-navbar-header" class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#LC-navbar-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 id="LC-navbar-brand" class="navbar-brand img-responsive" href="../">
<img class="img-responsive" src="../assets/img/logo-horizontal.png">
</a>
</div>
<div id="LC-navbar-collapse" class="collapse navbar-collapse">
<ul id="LC-navbar-links" class="nav navbar-nav navbar-right">
<li>Home</li>
<li class="active">Shop</li>
<li>Our Team</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
</div>
</nav>
And CSS:
#LC-navbar {
background-color: #202020;
border: none;
}
.navbar-brand {
padding-left: 30px;
}
#LC-navbar-links {
padding-right: 20px;
}
#LC-navbar-links li {
padding: 16px 10px;
}
#LC-navbar-links a {
font-size: 16px;
font-weight: 300;
text-transform: uppercase;
color: #c0c0c0;
-webkit-transition: color 0.25s;
-moz-transition: color 0.25s;
-o-transition: color 0.25s;
transition: color 0.25s;
}
#LC-navbar-links a:hover {
color: #BE1E2D;
}
#LC-navbar-links .active > a {
color: #BE1E2D;
background: none;
}
#LC-navbar-links .active > a:hover {
color: #BE1E2D;
background: none;
}
How would I go about changing styles to the navbar when it's collapsed? Obviously to change the overhang problem but also if say I want it to have a different background color when collapsed vs when open?
The toggle menu appears lesser than the width of 768px, so use the max-width: 768px media-query.
#media (max-width: 768px) {
.navbar-brand {
height: 80px; // Logo will not overhang
}
#LC-navbar {
background-color: #ccc; // Change background color
}
.navbar-toggle {
margin-top: 25px; // Adjust toggle position
}
}
I am trying to code a bootstrap navigation structure with 9 (don't laugh at my client please) buttons.
I want the first 5 buttons on top of the other 4, aligned to the right. The problem is that when I align them to the right, the buttons reverse in order. I solved this by creating two different lists, but that makes it reverse it when making the screen smaller. I think there should be a simple solution, but I can't find it. You can see an example at: http://www.sanderfish.nl/haptokuijpers/index.html
Here is my HTML:
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-left 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.html"><img src="assets/img/logo.png"</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Voor wie</li>
<li>Psychosomatiek</li>
<li>Haptotherapie</li>
<li>Diana Kuijpers</li>
<li>Vergoeding</li>
<li>Klachtenlijsten</li>
<li>Uitgeverij VIB</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
And this is the CSS:
#media (min-width: 768px) {
.navbar-nav {
float: right;
margin: 0;
text-align: right;
}
.navbar-nav > li {
float: left;
text-align: right;
}
.navbar-nav > li > a {
padding-top: 20px;
padding-bottom: 10px;
display: block;
text-align: right;
}
.navbar-nav.navbar-right:last-child {
margin-right: 0px;
text-align: right;
}
}
#media (min-width: 768px) {
.navbar-left {
float: left !important;
}
.navbar-right {
float: right !important;
padding-right: 34px;
text-align: right;
max-width: 750px;
}
}
Thanks in advance!
You don't need any custom CSS, just separate the two chunks of links into separate navbar-navs, and do navbar-right on the one you want to the right: DEMO: http://www.bootply.com/X0kDjEwnga
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>Voor wie</li>
<li>Psychosomatiek</li>
<li>Haptotherapie</li>
<li>Diana Kuijpers</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Vergoeding</li>
<li>Klachtenlijsten</li>
<li>Uitgeverij VIB</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
You may need to address their overlap when at specific in-between widths, but that's another story.
I don't understand why are you doing this since you're overriding not only Bootstrap, but the concept of responsive design altogether, but you'll know. Anyways, simply change this part:
.navbar-inverse .navbar-nav > li > a {
color: #FFF;
float: right;
}
to
.navbar-inverse .navbar-nav > li > a {
color: #FFF;
float: left;
}
I have a simple top-fixed nav using Bootstrap 3.0 which utilizes the submenu feature. I'm attempting to have my submenu take up the full width of the container, not just the width of the combined submenu elements. The problem appears to be coming from the ul.dropdown-menu code in which the width is set to ~160px; Not only that, but it refuses to extend left, past the dropdown menu tab. This is a problem because my collapse-nav is set to sit on the right side. Oy.
Below is a fiddle of my current solution.
FIDDLE FIDDLE, YA'LL
HTML:
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-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" href="index.html"></a>
</div>
<div class="navbar-collapse collapse pull-right">
<ul class="nav navbar-nav">
<li class="dropdown active">
Films <b class="caret"></b>
<ul class="dropdown-menu">
<div class="container">
<ul class="list-inline">
<li class="placeholder" id="pause"></li>
<li class="placeholder" id="hiccup"></li>
<li class="placeholder"></li>
<li class="placeholder"></li>
<li class="placeholder"></li>
<li class="placeholder"></li>
</ul>
</div>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
CSS (sorry it's so specific, I'm using SASS):
.navbar.navbar-default.navbar-fixed-top {
background-color: #454545;
border: none;
}
.navbar.navbar-default.navbar-fixed-top .container .navbar-collapse.collapse.pull-right ul.nav.navbar-nav li.active a, .navbar.navbar-default.navbar-fixed-top .container .navbar-collapse.collapse.pull-right ul.nav.navbar-nav li a:hover {
color: #ffcc00;
background-color: #454545;
height: inherit;
}
.navbar.navbar-default.navbar-fixed-top .container .navbar-collapse.collapse.pull-right ul.nav.navbar-nav li.dropdown.active.open ul.dropdown-menu {
list-style-type: none;
width: 100%;
background-color: white;
}
.navbar.navbar-default.navbar-fixed-top .container .navbar-collapse.collapse.pull-right ul.nav.navbar-nav li.dropdown.active.open ul.dropdown-menu .container {
background-color: white;
}
.navbar.navbar-default.navbar-fixed-top .container .navbar-collapse.collapse.pull-right ul.nav.navbar-nav li.dropdown.active.open ul.dropdown-menu .container ul.list-inline {
list-style-type: none;
width: 100%;
}
.navbar.navbar-default.navbar-fixed-top .container .navbar-collapse.collapse.pull-right ul.nav.navbar-nav li.dropdown.active.open ul.dropdown-menu .container ul.list-inline li.placeholder {
margin: 0 20px;
height: 100px;
width: 70px;
background-color: #999999;
}
So far the closest solution I've come across is adding a container within the dropdown menu, however I'm still unable to extend the dropdown menu beyond it's ~160px width.
The general goal is to have a full-width dropdown menu. Currently not worried about what it looks like on mobile devices.
Thanks
I use Yamm3 to do this, it's quite easy to integrate and allows you to specify a full width for your mega menu.
http://geedmo.github.io/yamm3/