Make items to disappear when clicking elsewhere - html

I've the following HTML NavBar:
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top navbar-custom" style="margin-bottom : 0px;">
<div class="container-fluid" ng-controller = "NavController">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> Menu <span ng-show="userCart.cart_size>0" style="color:orange">({{userCart.cart_size}}) </span><i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="#page-top">XYZ IoT</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="hidden">
</li>
<li class="page-scroll">
Products
</li>
<li class="page-scroll">
About
</li>
<li class="page-scroll">
Contact
</li>
<!-- Add the Login Anchor -->
<li ng-if="!userInfo.authorization">
Login
</li>
<li ng-if="userInfo.authorization">
My Devices
</li>
<li ng-if="userInfo.authorization">
Logout
</li>
</ul>
</div>
</div> <!-- /.navbar-collapse -->
</nav>
The problem is : When the compressed Nav appears, and I click on it, the menu items appear -- so far fine. But as soon I click else where, the menu stays as is. I have to click on the Menu (3 lines) to make menu items to disappear.
Can it be accomplished? I'm using bootstrap

Related

Navbar changes color when dropdown menu is added

I have a nav bar that is black on my main page, but when I go to another page (with a dropdown) the nav bar changes to white. How can I keep it black on both pages?
link to main page: index.html
link to letters: slider.html.php
nav bar code of index.html
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- 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">
<span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="#page-top">German War Letters</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#contact">Where to find the book</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
nav bar code of slider.html.php
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- 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">
<span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="index.html#page-top">German War Letters</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<!--PAUL DROPDOWN CHAPTERS-->
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Chapters
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Introduction</li>
<li>Chapter 2 The Heller Family</li>
<li>Chapter 3 Heinrich Bredemeier</li>
<li>Chapter 4 The Ketschau Family</li>
<li>Chapter 5 Rudolf Zwingenberger</li>
<li>Chapter 6 The Jagel Family</li>
<li>Chapter 7 Erich Kohler</li>
<li>Chapter 8 Sgt. Walfried Glase</li>
<li>Chapter 9 Moments in Time</li>
<li>Chapter 10 The Homefront</li>
<li>Chapter 11 Into the Abyss</li>
<li>Chapter 12 So why did they fight?</li>
</ul>
<!--END PAUL-->
<li>
<a class="page-scroll" href="index.html#about">About</a>
</li>
<li>
<a class="page-scroll" href="index.html#contact">Where to find the book</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>

Bootstrap dropdown-menu - full width and central horizontal items

My navbar below has a dropdown-menu which displays a horizontal list of <li> elements
<ul class="dropdown-menu">
How can I ensure that the dropdown-menu acts the same was as the div container class? ie: full width of the screen with the items centralised?
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css';
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="true">
<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-left" href="/home/"><span class="logo"></span></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-collapse collapse in" id="bs-example-navbar-collapse-1" aria-expanded="true" style="">
<ul class="nav navbar-nav navbar-right">
<li class="">
Option 1
</li>
<li class="">
Option 2
</li>
<li class="">
Option 3
</li>
<li class="dropdown">More...<span class="caret"></span>
<ul class="dropdown-menu">
<li class="">
Dropdown 1
</li>
<li class="">
Dropdown 2
</li>
<li class="">
Dropdown 3
</li>
<li class="">
Dropdown 4
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Take a look at Yamm Menu for Bootstrap , this is what you will need.

Boostrap navbar doesn't adjust width well

I dont't know why incrementing the width on my navbar the incrementation only occur on the right side of the bar, for example, this is my html of my bar:
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li>
Free shipping over $50
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a class ="lita" href="#about">Be part of THE CIRLCE</a>
</li>
<li>
JOIN
</li>
<li>
LOGIN
</li>
</ul>
</div>
Using this css:
#bs-example-navbar-collapse-1{
background-color: #fde6dc;
padding: 2px 40px;
width: 100%;
}
The result is this one:
http://postimg.org/image/m7qu1vz45/full/
But, if I move the width by 150%, this happen:
http://postimg.org/image/60px3u3m9/full/
Why is this happening? Why it doesn't adjust keeping the ratio, if I put a margin It kind of resolve the problem, but when I re-size the screen it doesn't work.
Anyone has an idea?
Please try this for navbar,
<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 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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li>
Free shipping over $50
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li>
<a class ="lita" href="#about">Be part of THE CIRLCE</a>
</li>
<li>
JOIN
</li>
<li>
LOGIN
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

How to fix my navbar

I have looked at other questions, but I just can't seem to fix the dropdown menu in my navbar.
I'm trying to make a dropdown menu like the one that is here, it's in the top right corner.
This is my code:
<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-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>
<!-- You'll want to use a responsive image option so this logo looks good on devices - I recommend using something like retina.js (do a quick Google search for it and you'll find it) -->
<a class="navbar-brand" href="#">Loveland Tigers</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 navbar-right">
<li>About</li>
<li class="dropdown">
Teams<b class="caret"></b>
<ul class="dropdown-menu">
<li>Freshman</li>
<li>Junior Varsity</li>
<li>Varsity</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container -->
</nav>
The dropdown menu does not show up when I click on the little arrow.
Remove those unneccessary classes from navbar-collapse div:
<div class="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>About</li>
<li class="dropdown"> Teams<b class="caret"></b>
<ul class="dropdown-menu">
<li>Freshman</li>
<li>Junior Varsity</li>
<li>Varsity</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
<!-- /.navbar-collapse -->
Working Fiddle.

Bootstrap navbar collapsing issue when there are some non collapsed items.

I'm trying to implement a menu in a webpage with Bootstrap that has some items which are not collapsed in extra-small screens.
I've been able to do progress implementing it. When the screen is extra-small, the items I want to not collapse are working as they should. But the problem is when I click on the navbar-toggle button, the collapsed menu shows up only on the right side of the screen and it's not screen wide as it normally is.
How can I fix this issue?
<nav role="navigation" class="navbar navbar-inverse">
<div class="container">
<!-- Title -->
<div class="navbar-header pull-left">
<a class="navbar-brand" href="#">Projeto</a>
</div>
<!-- 'Sticky' (non-collapsing) right-side menu item(s) -->
<div class="navbar-header pull-right">
<ul class="nav navbar-nav pull-left">
<li class="pull-left"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> </li>
</ul>
<!-- Required bootstrap placeholder for the collapsed menu -->
<button type="button" style="margin-left:20px;" 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>
<!-- The Collapsing items navbar-left or navbar-right -->
<div class="collapse navbar-collapse navbar-left">
<ul class="nav navbar-nav pull-right">
<li class="active">Inicio</li>
<li class="dropdown">
O Curso <span class="caret"></span>
<ul class="dropdown-menu">
<li>Sobre o Curso</li>
<li>Disciplinas</li>
</ul>
</li>
<li>Professores</li>
<li>Laboratórios</li>
</ul>
</div>
</div>
</nav>
Try adding navbar-fixed-top with a margin to the top of the collapsed div.