Why doesn't the bootstrap navbar mobile menu appear? - html

I have two questions. The first and the most important is how to make the menu in the minified version to appear. And the second thing I want is for the navbar to stay on the top when I scroll down and to turn black from transparent that it is now.
The Code is:
<nav class="navbar-inner navbar-inverse">
<div class="container">
<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="#">Cosmos</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
and the css is:
.navbar-inner {
background: transparent;
position: absolute;
top: 0;
right: 0;
left: 0;
z-index: 1;
}
You can also check the codepen page of the project:
https://codepen.io/georgekech/pen/ZLNMGE

Answer to both your questions:
While using bootstrap responsiveness is already handled. If provided the right markup on your HTML, bootstrap will take care of the menu on mobile view. Hence when you resize down to the mobile view, there would be a "hamburger menu" on the right of your navbar which toggles your menu options.
Next, If you want your header to stay on the top when you scroll down. Bootstrap already provides it. You just have to replace the class navbar-inverse with navbar-fixed-top on your <nav>. Also importantly remove the unnecessary position: absolute properties given to the navbar-inner
.navbar-inner {
background: transparent;
position: absolute; //remove
top: 0; //remove
right: 0; //remove
left: 0; //remove
z-index: 1;
}
Next, to change the background of the navbar when you scroll you need to add 2 simple changes, one to your JavaScript(using JQuery) another to your CSS, these 2 changes going hand in hand.
JQuery:
$(function () {
$(document).scroll(function () {
var $nav = $(".navbar-fixed-top");
$nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
});
});
CSS:
.navbar-fixed-top.scrolled {
background: black;
}
The Jquery will basically add/remove(toggle) a class to your navbar when you scroll more than the height of the navbar. Ofcourse the CSS is to just add the background color when the class is added from the JQuery.
Your codepen here
Note:
Obviously don't forget to include the JQuery library for the JavaScript to work, alternatively you can do the same using plain JavaScript.
If you do include JQuery, since you're using Bootstrap v3.3.6, JQuery version needs to be higher than 1.9.1 but also lower than 3. All of which you can find here
Done deal !

Try Following Code
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<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"></script>
<!-- Bootstrap Navigation Start -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<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="#">Cosmos</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<div>
<ul id="menu-hover" class="nav navbar-nav">
<li>Home</li>
<li>Public Service</li>
<li>Idea SubMission</li>
<li>Power Division</li>
</ul>
</div>
</div>
</div> <!-- End Navbar Collapse -->
</nav>
<!--End Bootstrap Navigation

.navbar-inner {
background: transparent;
position: absolute;
top: 0;
right: 0;
left: 0;
z-index: 1;
}
.navbar-inner position fixed will make your menu stable even if you will scroll down.
To change menu color on scroll, please check this answer of this menu background change color on scroll.

You need to use the same name used as the data-target in the button as the id of the div for the menu. In this case, it is "bs-example-navbar-collapse-1"
So add id="bs-example-navbar-collapse-1 to the div class="collapse navbar-collapse"
For the navbar, you don't need to use CSS if you are using bootstrap for what you want. Add the class of "navbar-fixed-top" to the nav element.
When you do use this class, you will need to add body {padding-bottom: 70px; }. This will push the content of your page to be under your navbar. 70px works with your example but change it as you see fit.

Related

Bootstrap toggable menu icon doesn't work on small device

i added at my hoe page a navbar with toggable icon on small screen; It is the typical navbar of bootstrap.
I have the problem that when i go on developer tool and resize the screen in order to test the responsive part, happen that the icon doesn't toggle, it is like is not active.
Any help?
Here is the code:
<nav id="header" class="navbar navbar-default">
<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="#navmenu" aria-expanded="false" aria-controls="navmenu">
<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 id="logo" src="images/art-of-hair.png"></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div id="navmenu" class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav">
<li class="active">Home<span class="sr-only">Home</span></li>
<li>Hair Styles</li>
<li class="">About</li>
<li class="">Contact</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
and css:
* {
margin: 0;
}
body {
font-family: 'Alice', serif;
}
#header {
height:200px;
}
#logo {
width: 300px;
height:150px;
}
#navmenu {
margin:30px 120px 0 0;
}
In case of toggle, I guess you also need some jQuery to make the toggle function.
Maybe try something like this:
<script>
$("button").click(function(){
$("#navmenu").slideToggle();
});
</script>

Removing Bottom Shadow Bootstrap Navbar

I am using Bootstrap's default navigation bar for my website. I would like the navbar and the content below the navbar to be the same color, without any demarcation between them. However, it appears that there is a shadow on the bottom of the navigation bar that I can't seem to get rid of.
I am using Bootstrap's default navbar template.
I have tried setting box-shadow: none; on each of the navbar classes I suspect (from inspecting the elements) may be causing this (.navbar, .navbar-default, and .container-fluid) to no avail.
nav {
box-shadow: none;
}
.navbar {
.container-fluid {
box-shadow: none;
}
box-shadow: none;
}
.navbar .navbar-collapse {
box-shadow: none;
}
.navbar .navbar-nav {
box-shadow: none;
}
.navbar-default {
box-shadow: none;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target=".navbar-collapse" 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="#">LOGO-GOES-HERE</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>LINK</li>
<li>LINK</li>
<li>LINK</li>
<li>LINK</li>
<li>LINK</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
I have also looked at Bootstrap's CSS and could not locate where the box-shadow is coming from.
Does anyone know any CSS I could write to remove this shadow from the bottom of the navigation bar, so that there is no line separating the navbar from the rest of the content?
Thank you so much for your time in advance.
This code is enough:
.navbar-default {
box-shadow: none;
}
But make sure that the code is placed after the link to bootstrap-theme.min.css. Otherwise your changes will not work.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css');
.navbar-default {
box-shadow: none;
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target=".navbar-collapse" 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="#">LOGO-GOES-HERE</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>LINK</li>
<li>LINK</li>
<li>LINK</li>
<li>LINK</li>
<li>LINK</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
You can try this link, it works. There is a shadow in the border.
https://getbootstrap.com/docs/4.3/utilities/shadows/
I tried like this, without any css as the solutions above. Just insert "shadow-none" as Documented.
<nav class="shadow-none navbar navbar-expand-sm ">
</nav>
Dont think there is a box shadow on the bootstrap navbar but there is a border have you tried
.navbar-default{
border:none;
}
You need to make sure that CSS commands are compatible with the browser. The browser compatibility description is given below.
The -moz-appearance CSS property is used in Gecko (Firefox) to display an element using platform-native styling based on the operating system's theme.
The -webkit-appearance property is used by WebKit-based (e.g., Safari) and Blink-based (e.g., Chrome, Opera) browsers to achieve the same thing. Note that Firefox and Edge also support -webkit-appearance, for compatibility reasons.
.navbar{
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
just add "shadow-none" class in the nav element
this one solved my problem.
.navbar-default {
background:none;
box-shadow: none;
}
If you just want to remove box-shadow from mdb-navbar do the following,
Inside your style.scss file in angular project paste the following code .navbar{ box-shadow: none!important; }

Making Navbar Transparent Bootstrap and Leftover chunks of color

Firstly: I've been trying to make the navbar transparent, looked up how to here, but the solutions haven't quite worked (or at least not as I expected). I'm using bootstrap, this is my HTML:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-inner">
<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>Overview</li>
<li>Features</li>
<li>Blog</li>
<li>FAQ</li>
<li>List</li>
</ul>
</div>
</div>
</div>
</nav>
I added in this custom CSS to change the navbar to transparent:
.navbar-inner {
background: transparent;
background-color: transparent;
border-width: 0px;
}
The CSS loads properly, but nothing changes in the navbar (at least I assumed it would be white, since the browser background is?)
I tried changing the background-color in the above CSS, and it did change it, but I got this result:
I'm wondering, even if I do get it transparent, how do I get rid of that bottom border (thought I set border-width to 0px already), and what are those black chunks on the side.
Thanks!
Use .navbar class insted of .navbar-inner, because Bootstrap has background on .navbar element.
.navbar {
background: none;
border: none;
}
Try using opacity: 0.5; in CSS.
you should try out the new css3 transparent feature "rgba" - the a stands for alpha channel
http://www.css3maker.com/css-3-rgba.html

Body not dropping below Bootstrap Navigation

Having CSS/HTML issues with Bootstrap. For some reason it seems the navigation is not pushing down the aspects of the HTML that follows. See https://jsfiddle.net/xaazf6u2/
<div id="topNavigation">
<nav class="navbar navbar-inverse 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="#">BCF</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">History <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>FGT</li>
<li>BB</li>
</ul>
</li>
</ul>
<ul id="login" class="nav navbar-nav navbar-right"></ul>
</div><!--/.nav-collapse -->
</div>
</nav>
</div>
<div id="pageContent" class="container">
<div class="jumbotron">
<h1>Welcome</h1>
<p>Use the form below to upload an order feed. Once uploaded, FedEx shipping will be purchased, labels and packing slip generated for us. Use the navigation above to access previously generated files.</p>
</div>
</div>
From the examples you can see that the jumbotron should have some space below the navigation http://getbootstrap.com/examples/theme/
When you used the fixed navbar Bootstrap recommends you add padding to your body to prevent this problem. So in your CSS you need to add
body { padding-top: 70px; }
The navbar is position:fixed so that it stays on the screen as you scroll. Elements with fixed position don't affect layout of other elements, so you'll need to manually set margin or padding on them.
See the Bootstrap documentation for notes on this.
Body padding required
The fixed navbar will overlay your other content, unless you add padding to the bottom of the <body>. Try out your own values or use our snippet below. Tip: By default, the navbar is 50px high.
Copy
body { padding-bottom: 70px; }
Make sure to include this after the core Bootstrap CSS.
The class "navbar-fixed-top" means that the content is scrollable and goes under the navbar.
Add a margin-top to the content if you want to keep this feature or remove the "navbar-fixed-top" class if you don't.
Navigation bar is fixed to the top by default you can change that by removing the class 'navbar-fixed-top'.

Position navigation from bootstrap left and right from an image

currently not knowing how to continue. I got an absolute positioned div element at the bottom of the page. I want to place a logo which is centered and also left and right from the logo i want to place the navigation ( i am working with bootstrap ). Here is an image from my idea so you can get a better view:
Here is my code of the position absolute div at the bottom. I kinda lost it pretty fast and appreciate every help i can get!
<div id="footmenu">
<div class="container navresize">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-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>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navleft">
<li>Home</li>
<li>Portfolio</li>
<li>Über uns</li>
<li></li>
<img src="images/logo.png" />
</ul>
</div>
</div>
</nav>
</div>
</div>
CSS:
#footmenu {
background:grey;
position: absolute;
bottom: 0;
width: 100%;
height: 150px;
}
( I deleted the rest of the css because i was pretty sure that it was wrong )
Again thanks for the help and i appreciate your time !
Edit: Will update the jsfiddle now. Here is a result i found which shows perfectly what i want to get: http://www.templatemonster.com/demo/39221.html
Here is the jsfiddle: http://jsfiddle.net/Su6VF/2/embedded/result/
You can try with inline-block display for the divs containing the list items and the logo and text-align:center to the wrapping div to position these in the center.
Check this FIDDLE
This might help you. Here is the styles used
.row{
text-align:center;
}
.col-md-4{
display:inline-block;
float:none;
width:auto;
}