I am working on creating a website using Bootstrap 3. The header is fixed both on laptop and mobile. But the items in the header are not showing up on mobile. Just a clean fixed header can be seen on the mobile device.
The Code I am using for the header is -
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container myContainer">
<div class="navbar-header">
<div class="collapse navbar-collapse mynavbar">
<ul class="nav navbar-nav myFont" >
<li>Values</li>
<li>Community</li>
<li class="mylogo"><img src="images/xyz-6.png" alt="" width="160px" height="50px" id="Logo"/></li>
<li>abc</li>
<li>Who are we</li>
</ul>
</div>
</div>
</div>
</nav>
And the customed CSS used is -
.mylogo{
margin-top : -15px;
}
.navbar-nav>li>a{
color: #000 !important;
font-size: 20px;
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
}
.navbar-nav>li{
padding: 5px 20px 5px 40px;
}
You can remove the collapse to show the whole menu on mobile, but you missed the mobile navbar menu button to have a proper mobile menu. See the Bootstrap documentation for more info and this Bootply link for a demo.
In short, add this code to your .navbar-header div:
<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>
<div class="collapse navbar-collapse mynavbar">
Remove two classes from this div (collapse and navbar-collapse).
Related
Sort of a weird issue that I can't seem to find an answer to online, so I'll see if anyone else here has experienced a similar problem.
I have a relatively tall bootstrap 3 navbar (110px in height) with a gradient background.
I want to add a 1px border to the bottom of the navbar just so it blends into my page a bit better, but for some reason when I do this there is a slight gap (appears to be about 1px) where I can see through the navbar to what's behind the page.
I tried to replicate the issue on codepen but for whatever reason, the issue isn't happening when I do it there so I included a screenshot below.
navbar issue
Not sure if you can make it out or not but there is a gap between the bottom of the navbar and the 1px border. I made the border in orange just so it's easier to see.
body {
font-family: 'Roboto', sans-serif;
font-size: 14px;
height:100%;
}
.navbar-default {
background: linear-gradient(0deg, rgba(77,77,77,1) 0%, rgba(0,0,0,1)
100%);
border-bottom: 1px solid orange;
height:110px;
padding:30px 0;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<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>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Products</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
If anyone has any helpful tips on how to perhaps remove this gapping it would be greatly appreciated!
I have this code for my navbar:
<nav class="navbar navbar-fixed-top" id="my-navbar">
<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>
<span class="icon-bar"></span>
</button>
<img style ="max-width:100px; margin-top: -7px;" src="images/firma-Edgar-Ayales.png" alt="">
</div><!--End navbar-header-->
<div class="collapse navbar-collapse navbar-right" id="navbar-collapse">
<ul class="nav navbar-nav">
<li>Feedback
<li>Gallery
<li>Features
<li>Faq
<li>ContactUs
</ul>
</div>
</div><!-- End container -->
And I want to change the links color, I tried this in my css:
.navbar {
background: rgba(0,0,0,0.4);
font-family: "Raleway";
font-size:10pt;
letter-spacing: 3pt;
color: black;
}
I also tried adding !important but I can't make it.
<nav class="navbar navbar-fixed-top" id="my-navbar">
<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>
<span class="icon-bar"></span>
</button>
<img style ="max-width:100px; margin-top: -7px;" src="images/firma-Edgar-Ayales.png" alt="">
</div><!--End navbar-header-->
<div class="collapse navbar-collapse navbar-right" id="navbar-collapse">
<ul class="nav navbar-nav" id="links">
<li>Feedback
<li>Gallery
<li>Features
<li>Faq
<li>ContactUs
</ul>
</div>
</div><!-- End container -->
CSS:
#links a{
color:#000000;
font-size:18px;
}
I just added id="links" to the ul, and then referenced the a's in that with CSS
You need to make your css more specific, color applied by bootstrap is on a. So overriding rule will be:
.navbar-nav > li >a{
color:black;
}
to override the default rule applied by bootstrap on anchor:
a {
color: #337ab7;
text-decoration: none;
}
Pen
This makes sure that this color is applied only to the anchor which is direct descendant of li which is direct descendant of .navbar-nav. In order to apply globally (all hyperlinks in your webpage), You could as well override by doing a{color:black}. You also need to make sure you are loading your css after bootstrap so that that takes the precedence over bootstrap. Avoid using !important it will destroy any cascadeability of the css and will prevent any overriding later on.
Here is a possible solution" https://jsfiddle.net/99x50s2s/52/
CSS:
.nav>li>a{
background: rgba(0,0,0,0.4);
font-family: "Raleway";
font-size:10pt;
letter-spacing: 3pt;
color: black;
}
The following code displays a navbar always on the top of the page.
I need the second container (content) to be positioned at the end of the navbar and not under it.
At the moment second container is under the navbar.
I could add some empty space on the top of the content are, but I am not sure it is a good approach.
Any idea how to solve it?
<div class="container">
<div class="row">
<div class="container">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
<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>
</nav>
</div>
</div>
<div class="row">
<div ng-view></div>
</div>
</div>
Updated 2018
Bootstrap 3
According to the Bootstrap docs (http://getbootstrap.com/components/#navbar-fixed-top) you should use padding-top on the body..
"The fixed navbar will overlay your other content, unless you add
padding to the top of the . Try out your own values or use our
snippet below. Tip: By default, the navbar is 50px high."
body { padding-top: 70px; }
Demo: http://www.bootply.com/Ob3Bajkv1f
Bootstrap 4
Padding is also recommended for the fixed-top Navbar in Bootstrap 4 to prevent content hiding at the top of the body. You can add custom CSS for padding-top or use the pt-5 utility class on the body tag:
<body class="pt-5"></body>
You would need some CSS like this:
body {
padding-top: 20px;
padding-bottom: 20px;
}
Or like this:
.navbar {
margin-bottom: 20px;
}
Make sure you only use what you need,
Just add margin-top: 50px; to the underlaying container.
50px has to be the height of your navbar.
I was able to solve this issue using the following code.
<div class="container">
<!-- navbar -->
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<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>
<a class="navbar-brand" href="#">KanbanBoard</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Boards</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>User</li>
</ul>
</div>
</div>
</nav>
<!-- boards -->
<div ng-view></div>
</div>
In Twitter bootstrap 2.3.2 I can have something like:
http://jsfiddle.net/aQwUZ/3/
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
BRAND
<ul class="nav pull-right">
<li>
Fixed Link
</li>
</ul>
<div class="nav-collapse">
<ul class="nav">
<li>L1</li>
<li>L2</li>
</ul>
</div>
</div>
</div>
</div>
A twitter bootstrap navbar, where in mobile responsive view, "Fixed Link" stay visible in header.
Now, in bootstrap 3, after upgrade my code, I can only have:
http://jsfiddle.net/EC3Ly/4/
<nav 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="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">BRAND</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li>
Fixed Link
</li>
</ul>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>L1</li>
<li>L2</li>
</ul>
</div>
</div>
</nav>
in mobile responsive view, I get 2 lines...
I tried to wrap in a "navbar-header" node http://jsfiddle.net/EC3Ly/5/ or in the first "navbar-header" without success.
What did I miss?
Thanks,
Alexandre
I faced the same problem with BS3, and the only way I found to resolve it was to use a combination of pull-left and pull-right
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header pull-left">
<a class="navbar-brand" href="#">BRAND</a>
</div>
<div class="navbar-header pull-right">
<ul class="nav navbar-nav pull-left">
<li>
Fixed Link
</li>
</ul>
<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>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>L1</li>
<li>L2</li>
</ul>
</div>
</div>
</nav>
Working demo: http://bootply.com/78856
The two lines in the mobile navbar are caused by the clearfix of the navbar-header:
.navbar-header {
.clearfix();
#media (min-width: #grid-float-breakpoint) {
float: left;
}
}
You could use media queries and css to undo this clearfix (and add a new before the collapsed dropdown)
.navbar-right {float: right !important;}
#media(max-width:767px)
{
.navbar-right {margin-right:20px;}
.navbar-header:after
{
clear: none;
}
.navbar-nav.navbar-right > li { float: left; }
.navbar-collapse:before {clear:both;}
.navbar-collapse {overflow-y: hidden;}
.navbar-collapse.in {overflow-y: visible;}
.navbar{border-color: #101010; border-width: 0 0 1px;}
.navbar-collapse.in > ul {border-color: #101010; border-top:1px double;}
}
}
demo: http://bootply.com/82366
The media queries also add a float right for the navbar-right on smaller screens. To take this code in production, you maybe will fix the borders and possible the navbar css transisions too.
The problem is with the point at which the navbar collapses. By default, Bootstrap collapses at 768px. If you increase this, your navbar will collapse sooner and your problem will disappear.
The best way to do this is to customize your bootstrap file and change the #grid-float-breakpoint to 850px (or whatever size you need). You can easily customize bootstrap 3 from http://getbootstrap.com/customize/?id=9720390
Hope this helps.
I fixed it this way. Just right after the brand add two new lines with the same class and an additional class.
<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">Home</a>
<!-- Fake branding to avoid breaking up navbar -->
<a class="navbar-brand navbar-brand-fake">Item 1</a>
<a class="navbar-brand navbar-brand-fake">Item 2</a>
And add this to your css file:
a.navbar-brand-fake {
font-size: 15px;
line-height: 21px;
margin-left: 2px !important;
}
Home, Item 1 and Item 2 remain in the navbar when resizing and the navbar won't break.
When I click on the toggle on my mobile page, the menu pops up for a brief moment and disappears again. Only the first item remains visible.
I took the css from thebootstrapthemes and basically just changed the colors and the content of the menu.
<div class="navbar-wrapper">
<div class="container">
<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="top-nav">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#home"><img src="#"></a>
<button type="button" class="navbar-toggle collapsed" 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>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="scroll">Home</li>
<li>Pronunciation</li>
<li>Downloads</li>
<li>Blog</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Any advice, how I can get my menu back?
This is my site
.navbar-nav {
margin-right: 0px !important;
height: 51px;
}
The 51px height is limiting your collapsible nav to show entirely.
** Not related to your question **
When using Bootstrap don't use row outside a container div since it will cause unnecessary horizontal scrollbars to appear.
Check your HTML for this element: #home #banner .centered .row. It's showing a scrollbar on my browser.