Menu sizing issues - html

I have a issue with my mega menu sizing. The desktop menu has a hover drop-down mega menu. The mega menus are going to be both 5 column and four column. I cant get the menu to size properly around the columns. currently its set close to what I'd like for the 5 column menu, however there is some text wrapping and id rather have the menu size itself appropriately. The four column has too much white space. I've tried a few things like switching width for max width but that doesn't solve the problem. Id really like to make the mega menu more responsive.
Codepen:https://codepen.io/iamgonge/pen/QpOgZB
desktop nav css:
/* Main Nav syle */
nav {
position: relative;
}
ul.main-nav {
list-style-type: none;
padding: 0px;
font-size: 0px;
max-width: 1000px;
margin: 0 auto;
}
ul.main-nav h2 {
font-size: .9em;
font-weight: 300;
}
ul.main-nav > li {
display: inline-block;
padding: 0;
}
ul.main-nav > li > a {
display: block;
padding: 20px 15px;
position: relative;
color: #fff;
font-size: 15px;
font-weight: 400;
box-sizing: border-box;
}
ul.main-nav > li:hover {
background-color: #f9f9f9;
}
ul.main-nav > li:hover > a {
color: #333;
font-weight: 400;
}
ul.main-nav > li ul.sub-menu-lists {
margin: 0px;
padding: 1px;
list-style-type: none;
display: block;
}
ul.main-nav > li ul.sub-menu-lists > li {
padding: 0 0px;
margin-top: 2px;
}
ul.main-nav > li ul.sub-menu-lists > li > a {
font-size: 14px;
}
.sub-menu-head {
margin: 10px 0;
border-bottom: 1px solid #4F96BA;
width: 100%;
}
/*Media Queries*/
#media only screen and (max-width: 768px) {
#top-logo {
display: block;
max-width: 50%;
margin: 3px auto;
}
.collapse.in {
min-height: 150px;
background-color:#4F96BA;
verflow-y:visible;
}
.sub-menu-head {
color: #fff;
}
nav {
background-color: transparent;
}
ul.main-nav > li > a:after {
display: none;
}
ul.main-nav > li:first-child {
border-radius: 0px;
}
ul.main-nav > li {
display: block;
border-bottom: 1px solid #444;
}
ul.main-nav > li > a {
font-weight: 600;
}
ul.main-nav > li ul.sub-menu-lists > li a {
color: #4F96BA;
;
font-size: 14px;
}
.sub-menu-head {
font-size: 16px;
}
ul.main-nav > li:hover {
background-color: transparent;
}
ul.main-nav > li:hover > a {
text-decoration: none;
font-weight: 600;
}
.sub-menu-block {
padding: 0 30px;
}
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: #000;
}
#big {
display: none;
}
}
/*end query*/
#media only screen and (min-width: 769px) {
#top-logo, #searchie {
display: none;
}
ul.main-nav {
display: block;
position: relative;
}
.sub-menu-block {
padding: 15px;
}
/* Sub Menu */
ul.main-nav > li > div.sub-menu-block {
visibility: hidden;
background-color: #f9f9f9;
position: absolute;
margin-top: 0px;
width: 100%;
color: #333;
left: 0;
box-sizing: border-box;
z-index: 3;
font-size: 16px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
opacity: 0;
/*CSS animation applied for sub menu : Slide from Top */
-webkit-transition: all 0.4s ease 0s;
-o-transition: all 0.4s ease 0s;
transition: all 0.4s ease 0s;
-webkit-transform: rotateX(90deg);
-moz-transform: rotateX(90deg);
-ms-transform: rotateX(90deg);
transform: rotateX(90deg);
-webkit-transform-origin: top center;
-ms-transform-origin: top center;
transform-origin: top center;
}
ul.main-nav > li:hover > div.sub-menu-block {
background-color: #f9f9f9;
visibility: visible;
opacity: 1;
-webkit-transform: rotateX(0deg);
-moz-transform: rotateX(0deg);
-ms-transform: rotateX(0deg);
transform: rotateX(0deg);
}
ul.main-nav > li > div.sub-menu-block > * {
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
-o-transition-property: opacity;
transition-property: opacity;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-o-transition-duration: 0.4s;
transition-duration: 0.4s;
opacity: 0;
}
ul.main-nav > li:hover > div.sub-menu-block > * {
opacity: 1;
}
.sub-menu-head {
font-size: 20px;
}
/* List Separator: Outer Border */
header.dark ul.main-nav > li > a {
border-right: 1px solid #bbb;
}
header.mega ul.main-nav > li > a {
border-right: 1px solid #666;
}
/* List Separator: Inner Border */
ul.main-nav > li > a:after {
content: '';
width: 1px;
height: 62px;
position: absolute;
right: 0px;
top: 0px;
z-index: 2;
}
header.dark ul.main-nav > li > a:after {
background-color: #777;
}
header.mega ul.main-nav > li > a:after {
background-color: #999;
}
/* Drop Down/Up Arrow for Mega Menu */
ul.main-nav > li > a.mega-menu > span {
display: block;
vertical-align: middle;
}
ul.main-nav > li > a.mega-menu > span:after {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #fff;
content: '';
background-color: transparent;
display: inline-block;
margin-left: 10px;
vertical-align: middle;
}
ul.main-nav > li:hover > a.mega-menu span:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 0px solid transparent;
border-bottom: 5px solid #666;
}
.banners-area {
border-top: 1px solid #ccc;
}
#little {
display: none;
}
}
/*end query*/
/**************Additions****************/
/* 5 Columns */
.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
position: relative;
min-height: 1px;
padding-right: 10px;
padding-left: 10px;
}
.col-xs-15 {
width: 20%;
float: left;
}
#media (min-width: 768px) {
.col-sm-15 {
width: 20%;
float: left;
}
}
#media (min-width: 992px) {
.col-md-15 {
width: 20%;
float: left;
}
}
#media (min-width: 1200px) {
.col-lg-15 {
width: 20%;
float: left;
}
}
html:
<div id="big">
<div class="navbar navbar-default navbar-static-top navbar-main affix-top" data-spy="affix" data-offset-top="50" role="navigation" >
<div class="dark">
<ul class="main-nav">
<li class="top-level-link">
<a class="mega-menu"><span>SOFTWARE</span></a>
<div class="sub-menu-block" id="five-block">
<div class="row">
<div class="col-md-15 col-sm-6">
<h2 class="sub-menu-head">Microsoft Office</h2>
<ul class="sub-menu-lists">
<li class="hover_drop_down">
Microsoft Office 2016<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Office 2016 Home & Business</li>
</ul>
</li>
<li>Microsoft Office 365 </li>
</ul>
</div>
<div class="col-md-15 col-sm-6">
<h2 class="sub-menu-head">Windows</h2>
<ul class="sub-menu-lists">
<li><a>Microsoft Windows 10 Pro</a></li>
</ul>
</div>
<div class="col-md-15 col-sm-6">
<h2 class="sub-menu-head">SQL Server</h2>
<ul class="sub-menu-lists">
<li><a>Microsoft SQL Server 2016<span class="caret"></span></a></li>
</ul>
</div>
<div class="col-md-15 col-sm-6">
<h2 class="sub-menu-head">Windows Server</h2>
<ul class="sub-menu-lists">
<li><a>Windows Server 2003 R2<span class="caret"></span></a></li>
</ul>
</div>
<div class="col-md-15 col-sm-6">
<h2 class="sub-menu-head">Remote Desktop Services</h2>
<ul class="sub-menu-lists">
<li><a>Remote Desktop Services 2016<span class="caret"></span></a></li>
</ul>
</div>
</div>
</div>
</li>
<li class="top-level-link">
<a class="mega-menu"><span>ELECTRONICS</span></a>
<div class="sub-menu-block">
<div class="row ">
<div class="col-md-3 col-sm-6" >
<h2 class="sub-menu-head">Software Resources</h2>
<ul class="sub-menu-lists" >
<li><a>Software Resources</a></li>
</ul>
</div>
<div class="col-md-3 col-sm-6" >
<h2 class="sub-menu-head">Software Resources</h2>
<ul class="sub-menu-lists" >
<li><a>Software Resources</a></li>
</ul>
</div>
<div class="col-md-3 col-sm-6" >
<h2 class="sub-menu-head">Software Resources</h2>
<ul class="sub-menu-lists" >
<li><a>Software Resources</a></li>
</ul>
</div>
<div class="col-md-3 col-sm-6" >
<h2 class="sub-menu-head">Software Resources</h2>
<ul class="sub-menu-lists" >
<li><a>Software Resources</a></li>
</ul>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<!--Desktop end-->

Can't you just remove the width:100% from the div.sub-menu-block element to remove the extra white-space from the 4-column menu?

Well you can use
white-space:nowrap;
For keeping the names in 1 line take a look here
CSS W3shcool attributes

Related

Dropdown of Navbar goes behind image slider

My dropdown menu goes behind the image slider part of my website. How can I get the dropdown in front of the image slider? I have also some other div's but they go like normally behind the dropdown menu of the Navbar. So I like to have the dropdown in front of the div of the image slider I made. I hope someone can help me
<--code html-->
<nav>
<div class="logo">
<div id="myMenu">
<div class="logo-navbar">
<nav>
<img src="images/logo-groot.png" height="80" />
</nav>
</div>
</div>
</div>
<label for="btn" class="icon">
<span class="fa fa-bars"></span>
</label>
<input type="checkbox" id="btn">
<ul>
<li>Home</li>
<li>
<label for="btn-2" class="show">Assortiment</label>
Assortiment
<input type="checkbox" id="btn-2">
<ul>
<li>Knalvuurwerk</li>
<li>Siervuurwerk</li>
<li>Kindervuurwerk</li>
</ul>
</li>
<li>Contact</li>
</ul>
</nav>
<div class="container">
<h1 id="headline">Nog <span id="days"></span> dagen tot start online vuurwerkverkoop</h1
<div id="countdown">
</div>
</div>
<div class="slideshow-container">
<!-- Full-width images with number and caption text -->
<div class="mySlides fade">
<a href="selectie.html"><img src="images/pyropapel-actie.png" style="width:100%">
</div>
<div class="mySlides fade">
<a href="contact.html"><img src="images/logo-groot.png" style="width:100%">
</div>
<div class="mySlides fade">
<a href="geschiedenis.html"><img src="images/logo-groot.png" style="width:100%">
</div>
<!-- Next and previous buttons -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<!-- The dots/circles -->
<div class="dots" style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
</div>
<-- css -->
nav{
background: #151515;
}
nav:after{
content: '';
clear: both;
display: table;
}
nav .logo{
float: left;
line-height: 70px;
padding-left: 60px;
}
nav ul{
float: right;
margin-right: 4px;
list-style: none;
position: relative;
}
nav ul li{
float: left;
display: inline-block;
background: #151515;
margin: 5 5px;
}
nav ul li a{
color: white;
line-height: 70px;
text-decoration: none;
font-size: 18px;
padding: 8px 15px;
}
nav ul li a:hover{
color: white;
border-radius: 5px;
box-shadow: 0 0 5px #000000,
0 0 10px #0a0a0a;
}
nav ul ul li a:hover{
box-shadow: none;
}
nav ul ul{
position: absolute;
top: 90px;
border-top: 3px solid red;
opacity: 0;
visibility: hidden;
transition: top .3s;
}
nav ul ul ul{
border-top: none;
}
nav ul li:hover > ul{
top: 70px;
opacity: 1;
visibility: visible;
}
nav ul ul li{
position: relative;
margin: 0px -20px;
width: 175px;
float: none;
display: list-item;
border-bottom: 1px solid rgba(0,0,0,0.3);
text-align:center;
}
nav ul ul li a{
line-height: 50px;
}
nav ul ul ul li{
position: relative;
top: -60px;
left: 150px;
}
.show,.icon,input{
display: none;
}
.fa-plus{
font-size: 15px;
margin-left: 40px;
}
#media all and (max-width: 968px) {
nav ul{
margin-right: 0px;
float: left;
}
nav .logo{
padding-left: 30px;
width: 100%;
}
.show + a, nav > ul{
display: none;
}
nav ul li,nav ul ul li{
display: block;
width: 100%;
}
nav ul li a:hover{
box-shadow: none;
}
.show{
display: block;
color: white;
font-size: 18px;
padding: 0 15px;
line-height: 70px;
cursor: pointer;
}
.show:hover{
color: white;
border-radius:5px;
}
.icon{
display: block;
color: white;
position: absolute;
top: 25;
right: 40px;
line-height: 70px;
cursor: pointer;
font-size: 25px;
}
nav ul ul{
top: 70px;
border-top: 0px;
float: none;
position: static;
display: none;
opacity: 1;
visibility: visible;
}
nav ul ul a{
padding-left: 40px;
}
nav ul ul ul a{
padding-left: 80px;
}
nav ul ul ul li{
position: static;
}
[id^=btn]:checked + ul{
display: block;
}
nav ul ul li{
border-bottom: 0px;
}
span.cancel:before{
content: '\f00d';
}
}
.slideshow-container {
position: relative;
margin: auto;
background-color: rgba(0, 0, 0, 1);
width:75%;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
align-items: center;
top: 50%;
width:auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
background-color: #bbb;
}
.active, .dot:hover {
background-color: #717171;
}
.dots{
background-color: rgba(23, 14, 13, 0.97);
width:75%;
align-items:center;
margin:auto;
padding-top: 20px;
margin-top:-24px;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
#-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

navigation submenu showing up before hovering parent

I have a horizontal nav bar and I set the submenu to show only when you hover over the parent but the submenus show up when I move my mouse even a couple inches below the parents. I'm not sure how to fix that.
HTML:
<body>
<header>
<div class="nav">
<ul class="mainmenu">
<li>Home</li>
<li>Photography
<ul class="submenu">
<li>Belize</li>
<li>Fernie BC</li>
<li>Montana</li>
<li>Philippines</li>
<li>Lake Tahoe</li>
<li>The Kids</li>
</ul>
</li>
<li>Woodworking
<ul class="submenu">
<li>Furniture</li>
<li>Cutting Boards</li>
<li>Bandsaw Boxes</li>
<li>Keepsake Boxes</li>
<li>Odds &amp Ends</li>
</ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</header>
</body>
</html>
CSS:
body {
background-color: rgb(51,51,51);
color: white;
}
.nav > ul {
list-style: none;
background-color: rgba(0, 0, 0, 0.6);
text-align: center;
padding: 10px;
width: 100%;
}
.nav > li {
width: 230px;
border-bottom: none;
height: 50px;
line-height: 40px;
display: inline-block;
margin-right: -4px;
}
.nav > ul > li {
list-style-type: none;
display:inline-block;
padding: 5px 35px 5px 35px;
position: relative;
text-align: left;
line-height: 40px;
font-size: 25px;
}
.nav > ul > li:hover {
background-color: #009933;
}
ul.submenu {
position: absolute;
background-color: #141414;
list-style-type: none;
width: 190px;
padding-left: 0px;
padding-top: 5px;
padding-right: 60px;
margin-top: 15px;
margin-left: -35px;
opacity: 0;
}
ul.submenu li {
padding-left: 25px;
padding-top: 5px;
padding-bottom: 5px;
}
.nav li:hover .submenu {
opacity: 1;
}
ul.submenu li:hover {
color: white;
}
.nav a {
text-decoration: none;
color: white;
display: block;
padding-left: 15px;
padding-right: 15px;
transition: .3s background-color;
}
.nav a:hover {
background-color: #009933;
color: black;
}
Will Advise adding the visibility property to be hidden on your "li" element. Opacity 0 still makes the "li" present and the "li" element extends with the submenu. See code below hope it helps.
body {
background-color: rgb(51,51,51);
color: white;
}
.nav > ul {
list-style: none;
background-color: rgba(0, 0, 0, 0.6);
text-align: center;
padding: 10px;
width: 100%;
}
.nav > li {
width: 230px;
border-bottom: none;
height: 50px;
line-height: 40px;
display: inline-block;
margin-right: -4px;
}
.nav > ul > li {
list-style-type: none;
display:inline-block;
padding: 5px 35px 5px 35px;
position: relative;
text-align: left;
line-height: 40px;
font-size: 25px;
}
.nav > ul > li:hover {
background-color: #009933;
}
ul.submenu {
position: absolute;
background-color: #141414;
list-style-type: none;
width: 190px;
padding-left: 0px;
padding-top: 5px;
padding-right: 60px;
margin-top: 15px;
margin-left: -35px;
opacity: 0;
visibility: hidden;
}
ul.submenu li {
padding-left: 25px;
padding-top: 5px;
padding-bottom: 5px;
}
.nav li:hover .submenu {
opacity: 1;
visibility: visible;
}
ul.submenu li:hover {
color: white;
}
.nav a {
text-decoration: none;
color: white;
display: block;
padding-left: 15px;
padding-right: 15px;
transition: .3s background-color;
}
.nav a:hover {
background-color: #009933;
color: black;
}
<body>
<header>
<div class="nav">
<ul class="mainmenu">
<li>Home</li>
<li>Photography
<ul class="submenu">
<li>Belize</li>
<li>Fernie BC</li>
<li>Montana</li>
<li>Philippines</li>
<li>Lake Tahoe</li>
<li>The Kids</li>
</ul>
</li>
<li>Woodworking
<ul class="submenu">
<li>Furniture</li>
<li>Cutting Boards</li>
<li>Bandsaw Boxes</li>
<li>Keepsake Boxes</li>
<li>Odds &amp Ends</li>
</ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</header>
</body>
Update your css change margin-top: 15px to margin-top: 5px
Set display: none; when it is hidding, so hover below the nav menu will not trigger it.
ul.submenu {
position: absolute;
background-color: #141414;
list-style-type: none;
width: 190px;
padding-left: 0px;
padding-top: 5px;
padding-right: 60px;
margin-top: 5px;
margin-left: -35px;
opacity: 0;
display: none;
}
Add this to your .submenu so when it should show set to display:block;:
.nav li:hover .submenu {
opacity: 1;
display: block;
z-index: 9999;
}
Now, the solution:
/* ************************************* HOME PAGE **************************************** */
#homeImage {
background: url("fernielow.jpg");
background-repeat: no-repeat;
background-size: cover;
font-family: 'Oswald', sans-serif;
color: white;
letter-spacing: 2px;
}
h1 {
background-color: rgba(0, 0, 0, 0.6);
text-align: center;
padding: 10px;
width: 99%;
margin-top: 450px;
}
h1 a {
text-decoration: none;
}
h1 a:visited {
text-decoration: none;
color: white;
}
h1 a:hover {
background-color: #009933;
padding: 10px 20px 10px 20px;
color: black;
}
h1 a:active {
text-decoration: underline;
}
/* ************************************* NAVIGATION **************************************** */
body {
background: url("");
background-color: rgb(51, 51, 51);
background-repeat: no-repeat;
background-size: cover;
font-family: 'Oswald', sans-serif;
color: white;
letter-spacing: 2px;
}
/* LOOK # NAV AND THEN # UL */
.nav>ul {
list-style: none;
background-color: rgba(0, 0, 0, 0.6);
text-align: center;
padding: 10px;
width: 100%;
}
.nav>li {
width: 230px;
border-bottom: none;
height: 50px;
line-height: 40px;
display: inline-block;
margin-right: -4px;
}
/* LOOK # NAV THEN # UL THEN # LI*/
.nav>ul>li {
list-style-type: none;
display: inline-block;
padding: 5px 35px 5px 35px;
position: relative;
text-align: left;
line-height: 40px;
font-size: 25px;
}
.nav>ul>li:hover {
background-color: #009933;
}
ul.submenu {
position: absolute;
background-color: #141414;
list-style-type: none;
width: 190px;
padding-left: 0px;
padding-top: 5px;
padding-right: 60px;
margin-top: 5px;
margin-left: -35px;
opacity: 0;
display: none;
}
ul.submenu li {
padding-left: 25px;
padding-top: 5px;
padding-bottom: 5px;
}
/* WHEN HOVER OVER NAV LIST, I WANT SUBMENU TO CHANGE */
.nav li:hover .submenu {
opacity: 1;
display: block;
z-index: 9999;
}
ul.submenu li:hover {
color: white;
}
.nav a {
text-decoration: none;
color: white;
display: block;
padding-left: 15px;
padding-right: 15px;
transition: .3s background-color;
}
.nav a:hover {
background-color: #009933;
color: black;
}
/* ************************************* CONTACT PAGE **************************************** */
#contactInfo ul {
list-style: none;
background: rgba(0, 0, 0, 0.8);
border: 5px black solid;
margin-top: 175px;
margin-left: 750px;
width: 300px;
}
.contactAddress {
font-size: 25px;
text-align: center;
padding: 10px;
display: inline-block;
line-height: 40px;
}
#contactInfo ul li a:link {
text-decoration: none;
background-color: rgba(0, 153, 51, 0.8);
padding: 1px 5px 1px 5px;
color: black;
font-weight: bold;
}
#contactInfo ul li a:visited {
text-decoration: none;
}
#contactInfo ul li a:hover {
text-decoration: underline;
}
#contactInfo ul li a:active {
text-decoration: underline;
}
/* ************************************* ABOUT PAGE **************************************** */
#aboutMe {
font-size: 25px;
text-align: center;
padding: 20px;
display: inline-block;
border: 5px black solid;
background-color: rgba(0, 0, 0, 0.8);
width: 800px;
margin-top: 50px;
margin-left: 550px;
line-height: 35px;
}
/* ************************************* PHOTOGRAPHY PAGE **************************************** */
.picContainer {
width: 1032px;
float: left;
margin-top: 50px;
margin-left: 23%;
background-color: rgba(0, 0, 0, 0.8);
border: 5px black solid;
}
.picContainer h2 {
text-align: center;
font-size: 30px;
}
.pic {
width: 300px;
height: 300px;
margin: 15px;
border: 5px black solid;
}
hr {
height: 10px;
border: 0;
box-shadow: 0 10px 10px -3px black inset;
}
/* ************************************* TOP TO PAGE **************************************** */
#myBtn {
display: none;
/* Hidden by default */
position: fixed;
/* Fixed/sticky position */
bottom: 50px;
/* Place the button at the bottom of the page */
right: 50px;
/* Place the button 30px from the right */
z-index: 99;
/* Make sure it does not overlap */
border: none;
/* Remove borders */
outline: none;
/* Remove outline */
background-color: white;
/* Set a background color */
color: black;
/* Text color */
cursor: pointer;
/* Add a mouse pointer on hover */
padding: 10px;
/* Some padding */
border-radius: 3px;
/* Rounded corners */
font-family: 'Oswald', sans-serif;
letter-spacing: 2px;
font-weight: bolder;
font-size: 15px;
}
#myBtn:hover {
background-color: #009933;
/* Add a dark-grey background on hover */
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="sawdust.css" />
<title>Sawdust &amp Splinters</title>
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<header>
<div class="nav">
<ul class="mainmenu">
<li>Home</li>
<li>Photography
<ul class="submenu">
<li>Belize</li>
<li>Fernie BC</li>
<li>Montana</li>
<li>Philippines</li>
<li>Lake Tahoe</li>
<li>The Kids</li>
</ul>
</li>
<li>Woodworking
<ul class="submenu">
<li>Furniture</li>
<li>Cutting Boards</li>
<li>Bandsaw Boxes</li>
<li>Keepsake Boxes</li>
<li>Odds &amp Ends</li>
</ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</header>
<button onclick="topFunction()" id="myBtn" title="Go to top">Go back to top</button>
<div class=picContainer>
<span id="belize">
<h2>BELIZE</h2>
<img class="pic" src="photos/belize/pano-thumb.jpg" alt="San Pedro Panoramic"/>
<img class="pic" src="photos/belize/broken-thumb.jpg" alt="San Pedro Broken Bridge"/>
<img class="pic" src="photos/belize/beach-thumb.jpg" alt="San Pedro Beach"/>
<img class="pic" src="photos/belize/ruins-thumb.jpg" alt="Xunantunich Ruins"/>
<img class="pic" src="photos/belize/zoo1-thumb.jpg" alt="San Pedro Zoo"/>
<img class="pic" src="photos/belize/zoo2-thumb.jpg" alt="San Pedro Zoo"/>
<img class="pic" src="photos/belize/zoo3-thumb.jpg" alt="San Pedro Zoo"/>
<img class="pic" src="photos/belize/zoo4-thumb.jpg" alt="San Pedro Zoo"/>
<img class="pic" src="photos/belize/cotton-tree-thumb.jpg" alt="Belize Cotton Tree"/>
</span>
<br>
<br>
<br>
<br>
<hr>
<span id="fernie">
<h2>FERNIE, BC</h2>
<img class="pic" src="photos/fernie/fernie-thumb.jpg" alt="Fernie"/>
</span>
<br>
<br>
<br>
<br>
<hr>
<span id="montana">
<h2>MONTANA</h2>
<img class="pic" src="photos/montana/dog-park-mtns-thumb.jpg" alt="Spanish Peaks"/>
<img class="pic" src="photos/montana/fairy-lake-bw-thumb.jpg" alt="Fairy Lake"/>
<img class="pic" src="photos/montana/gallatin-thumb.jpg" alt="Gallatin River"/>
<img class="pic" src="photos/montana/grotto-thumb.jpg" alt="Grott Falls"/>
<img class="pic" src="photos/montana/hyalite-thumb.jpg" alt="Hyalite River"/>
<img class="pic" src="photos/montana/mtns-thumb.jpg" alt="Mountains"/>
<img class="pic" src="photos/montana/natural-thumb.jpg" alt="Natural Bridge Falls"/>
<img class="pic" src="photos/montana/palisades1-thumb.jpg" alt="Palisades Mountain"/>
<img class="pic" src="photos/montana/palisades2-thumb.jpg" alt="Palisades Falls"/>
<img class="pic" src="photos/montana/sunset1-thumb.jpg" alt="Sunset"/>
<img class="pic" src="photos/montana/sunset2-thumb.jpg" alt="Sunset"/>
<img class="pic" src="photos/montana/sunset3-thumb.jpg" alt="Sunset"/>
</span>
<br>
<br>
<br>
<br>
<hr>
<span id="philippines">
<h2>PHILIPPINES</h2>
<img class="pic" src="photos/philippines/temple-thumb.jpg" alt="Sunken Temple"/>
<img class="pic" src="photos/philippines/katibawasan-thumb.jpg" alt="Katibawasan Falls"/>
<img class="pic" src="photos/philippines/camiguin1-thumb.jpg" alt="Camiguin"/>
<img class="pic" src="photos/philippines/camiguin2-thumb.jpg" alt="Camiguin"/>
<img class="pic" src="photos/philippines/camiguin3-thumb.jpg" alt="Camiguin"/>
<img class="pic" src="photos/philippines/camiguin4-thumb.jpg" alt="Camiguin"/>
<img class="pic" src="photos/philippines/camiguin5-thumb.jpg" alt="Camiguin"/>
</span>
<br>
<br>
<br>
<br>
<hr>
<span id="tahoe">
<h2>LAKE TAHOE</h2>
<img class="pic" src="photos/tahoe/tahoe1-thumb.jpg" alt="Lake Tahoe"/>
<img class="pic" src="photos/tahoe/tahoe2-thumb.jpg" alt="Lake Tahoe"/>
<img class="pic" src="photos/tahoe/tahoe3-thumb.jpg" alt="Lake Tahoe"/>
<img class="pic" src="photos/tahoe/tahoe4-thumb.jpg" alt="Lake Tahoe"/>
<img class="pic" src="photos/tahoe/tahoe5-thumb.jpg" alt="Lake Tahoe"/>
</span>
</div>
</body>
</html>
Just add visibility:hidden; and visibility:visible;
ul.submenu {
position: absolute;
background-color: #141414;
list-style-type: none;
width: 190px;
padding-left: 0px;
padding-top: 5px;
padding-right: 60px;
margin-top: 15px;
margin-left: -35px;
opacity: 0;
visibility:hidden; //add this
}
.nav li:hover .submenu {
opacity: 1;
visibility:visible; //add this
}
$("#cssmenu").menumaker({
title: "Menu",
breakpoint: 768,
format: "multitoggle"
});
#import url(https://fonts.googleapis.com/css?family=Montserrat:400,700);
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a,
#cssmenu #menu-button {
margin: 0;
padding: 0;
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#cssmenu:after,
#cssmenu > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#cssmenu #menu-button {
display: none;
}
#cssmenu {
font-family: Montserrat, sans-serif;
background: #333333;
}
#cssmenu > ul > li {
float: left;
}
#cssmenu.align-center > ul {
font-size: 0;
text-align: center;
}
#cssmenu.align-center > ul > li {
display: inline-block;
float: none;
}
#cssmenu.align-center ul ul {
text-align: left;
}
#cssmenu.align-right > ul > li {
float: right;
}
#cssmenu > ul > li > a {
padding: 17px;
font-size: 12px;
letter-spacing: 1px;
text-decoration: none;
color: #dddddd;
font-weight: 700;
text-transform: uppercase;
}
#cssmenu > ul > li:hover > a {
color: #00ff00;
}
#cssmenu > ul > li.has-sub > a {
padding-right: 30px;
}
#cssmenu > ul > li.has-sub > a:after {
position: absolute;
top: 22px;
right: 11px;
width: 8px;
height: 2px;
display: block;
background: #dddddd;
content: '';
}
#cssmenu > ul > li.has-sub > a:before {
position: absolute;
top: 19px;
right: 14px;
display: block;
width: 2px;
height: 8px;
background: #dddddd;
content: '';
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#cssmenu > ul > li.has-sub:hover > a:before {
top: 23px;
height: 0;
}
#cssmenu ul ul {
position: absolute;
left: -9999px;
}
#cssmenu.align-right ul ul {
text-align: right;
}
#cssmenu ul ul li {
height: 0;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#cssmenu li:hover > ul {
left: auto;
}
#cssmenu.align-right li:hover > ul {
left: auto;
right: 0;
}
#cssmenu li:hover > ul > li {
height: 35px;
}
#cssmenu ul ul ul {
margin-left: 100%;
top: 0;
}
#cssmenu.align-right ul ul ul {
margin-left: 0;
margin-right: 100%;
}
#cssmenu ul ul li a {
border-bottom: 1px solid rgba(150, 150, 150, 0.15);
padding: 11px 15px;
width: 170px;
font-size: 12px;
text-decoration: none;
color: #dddddd;
font-weight: 400;
background: #333333;
}
#cssmenu ul ul li:last-child > a,
#cssmenu ul ul li.last-item > a {
border-bottom: 0;
}
#cssmenu ul ul li:hover > a,
#cssmenu ul ul li a:hover {
color: #00ff00;
}
#cssmenu ul ul li.has-sub > a:after {
position: absolute;
top: 16px;
right: 11px;
width: 8px;
height: 2px;
display: block;
background: #dddddd;
content: '';
}
#cssmenu.align-right ul ul li.has-sub > a:after {
right: auto;
left: 11px;
}
#cssmenu ul ul li.has-sub > a:before {
position: absolute;
top: 13px;
right: 14px;
display: block;
width: 2px;
height: 8px;
background: #dddddd;
content: '';
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#cssmenu.align-right ul ul li.has-sub > a:before {
right: auto;
left: 14px;
}
#cssmenu ul ul > li.has-sub:hover > a:before {
top: 17px;
height: 0;
}
#cssmenu.small-screen {
width: 100%;
}
#cssmenu.small-screen ul {
width: 100%;
display: none;
}
#cssmenu.small-screen.align-center > ul {
text-align: left;
}
#cssmenu.small-screen ul li {
width: 100%;
border-top: 1px solid rgba(120, 120, 120, 0.2);
}
#cssmenu.small-screen ul ul li,
#cssmenu.small-screen li:hover > ul > li {
height: auto;
}
#cssmenu.small-screen ul li a,
#cssmenu.small-screen ul ul li a {
width: 100%;
border-bottom: 0;
}
#cssmenu.small-screen > ul > li {
float: none;
}
#cssmenu.small-screen ul ul li a {
padding-left: 25px;
}
#cssmenu.small-screen ul ul ul li a {
padding-left: 35px;
}
#cssmenu.small-screen ul ul li a {
color: #dddddd;
background: none;
}
#cssmenu.small-screen ul ul li:hover > a,
#cssmenu.small-screen ul ul li.active > a {
color: #00ff00;
}
#cssmenu.small-screen ul ul,
#cssmenu.small-screen ul ul ul,
#cssmenu.small-screen.align-right ul ul {
position: relative;
left: 0;
width: 100%;
margin: 0;
text-align: left;
}
#cssmenu.small-screen > ul > li.has-sub > a:after,
#cssmenu.small-screen > ul > li.has-sub > a:before,
#cssmenu.small-screen ul ul > li.has-sub > a:after,
#cssmenu.small-screen ul ul > li.has-sub > a:before {
display: none;
}
#cssmenu.small-screen #menu-button {
display: block;
padding: 17px;
color: #dddddd;
cursor: pointer;
font-size: 12px;
text-transform: uppercase;
font-weight: 700;
}
#cssmenu.small-screen #menu-button:after {
position: absolute;
top: 22px;
right: 17px;
display: block;
height: 4px;
width: 20px;
border-top: 2px solid #dddddd;
border-bottom: 2px solid #dddddd;
content: '';
box-sizing: content-box;
}
#cssmenu.small-screen #menu-button:before {
position: absolute;
top: 16px;
right: 17px;
display: block;
height: 2px;
width: 20px;
background: #dddddd;
content: '';
box-sizing: content-box;
}
#cssmenu.small-screen #menu-button.menu-opened:after {
top: 23px;
border: 0;
height: 2px;
width: 15px;
background: #00ff00;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#cssmenu.small-screen #menu-button.menu-opened:before {
top: 23px;
background: #00ff00;
width: 15px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#cssmenu.small-screen .submenu-button {
position: absolute;
z-index: 99;
right: 0;
top: 0;
display: block;
border-left: 1px solid rgba(120, 120, 120, 0.2);
height: 46px;
width: 46px;
cursor: pointer;
}
#cssmenu.small-screen .submenu-button.submenu-opened {
background: #262626;
}
#cssmenu.small-screen ul ul .submenu-button {
height: 34px;
width: 34px;
}
#cssmenu.small-screen .submenu-button:after {
position: absolute;
top: 22px;
right: 19px;
width: 8px;
height: 2px;
display: block;
background: #dddddd;
content: '';
}
#cssmenu.small-screen ul ul .submenu-button:after {
top: 15px;
right: 13px;
}
#cssmenu.small-screen .submenu-button.submenu-opened:after {
background: #00ff00;
}
#cssmenu.small-screen .submenu-button:before {
position: absolute;
top: 19px;
right: 22px;
display: block;
width: 2px;
height: 8px;
background: #dddddd;
content: '';
}
#cssmenu.small-screen ul ul .submenu-button:before {
top: 12px;
right: 16px;
}
#cssmenu.small-screen .submenu-button.submenu-opened:before {
display: none;
}
#cssmenu.small-screen.select-list {
padding: 5px;
}
<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- jQuery -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<!-- MenuMaker Plugin -->
<script src="https://s3.amazonaws.com/menumaker/menumaker.min.js"></script>
<!-- Icon Library -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="cssmenu">
<ul>
<li><i class="fa fa-fw fa-home"></i> Home</li>
<li><i class="fa fa-fw fa-camera"></i> Photography
<ul>
<li>Belize</li>
<li>Fernie BC</li>
<li>Montana</li>
<li>Philippines</li>
<li>Lake Tahoe</li>
<li>The Kids</li>
</ul>
</li>
<li><i class="fa fa-fw fa-magic"></i> Woodworking
<ul>
<li>Furniture</li>
<li>Cutting Boards</li>
<li>Bandsaw Boxes</li>
<li>Keepsake Boxes</li>
<li>Odds & Ends</li>
</ul>
</li>
<li><i class="fa fa-fw fa-info"></i> About</li>
<li><i class="fa fa-fw fa-phone"></i> Contact</li>
</ul>
</div>
</body>
</html>

Navbar Dropdown List Items Appearing Aligned Left Before Animation

I would like my navbar dropdown menu to take up the entire browsing area with the list items centered, and have a brief animation during the transition.
For the animation, I want the .icon-bar hamburger menu to transition to an "X" and for the dropdown menu to have a cubic-bezier transition.
However, the list items first appear aligned left prior to the animation.
Wondering why the list is left-aligned prior to animation.
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Quicksand', sans-serif;
}
body {
margin-top: 60px;
}
#main-wrapper {
display: flex;
flex-direction: column;
min-height: 100%;
}
.container {
margin: 0 auto;
}
.article {
flex: 1;
}
/*START Shrinks the default navbar height*/
.navbar {
//min-height: 30px;
margin: 0px;
width: 100%;
background-color: #444;
//height: 44px;
}
.navbar-nav > li,
.navbar-nav > li > a,
.navbar-nav > li > a:link,
.navbar-nav > li > a:visited {
padding: 4px 5px 0px 5px;
//height: 30px;
color: white;
font-size: 1.1em;
font-weight: 300;
margin: 2px 8px 0 0;
}
/*END*/
.nav.navbar-nav li a:focus,
.nav.navbar-nav li a:active,
.nav.navbar-nav li a:hover {
color: white;
opacity: 0.8;
}
.navbar-toggle {
float: left;
border: none;
margin-top: 10px;
margin-left: 10px;
padding: 4px;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:active,
.navbar-default .navbar-toggle:focus {
background-color: #444;
}
/*Displays navbar dropdown on hover */
ul.nav li.dropdown:hover ul.dropdown-menu {
display: block;
}
.navbar-default .navbar-header .icon-bar {
background-color: white;
width: 22px;
}
.navbar-default .navbar-toggle:hover .icon-bar {
background-color: #EFEFEF;
}
.navbar .navbar-brand {
color: white;
margin: -4px 20px -3px 0;
font-size: 1.7em;
font-family: 'Orbitron', 'Dosis', sans-serif;
}
.navbar .navbar-brand:focus,
.navbar .navbar-brand:hover {
color: white;
opacity: 0.8;
}
.fa-caret-down {
height: 30px;
color: lightGray;
}
/*Change hamburger menu to "x" on click */
.navbar-toggle .icon-bar {
width: 22px;
transition: all 0.4s;
}
.navbar-toggle .top-bar {
transform: rotate(405deg);
transform-origin: 10% 10%;
}
.navbar-toggle .middle-bar {
opacity: 0;
}
.navbar-toggle .bottom-bar {
transform: rotate(-405deg);
transform-origin: 10% 90%;
}
.navbar-toggle.collapsed .top-bar {
transform: rotate(0);
}
.navbar-toggle.collapsed .middle-bar {
opacity: 1;
}
.navbar-toggle.collapsed .bottom-bar {
transform: rotate(0);
}
.navbar.navbar-default .navbar-collapse {
border: none;
box-shadow: none;
}
/*Change Background color of toggle dropdown*/
.collapse.navbar-collapse {
background-color: #444;
min-width: 100%;
min-height: 100%;
}
h3 + p {
line-height: 1.8em;
}
footer {
background-color: #444;
color: white;
height: 250px;
padding: 8px;
}
footer a,
footer a:link,
footer a:visited {
color: white;
text-decoration: none;
}
footer a:hover,
footer a:active,
footer a:focus {
opacity: 0.8;
}
.tagline {
text-align: center;
}
.footer-sub {
border: thin white solid;
margin: 0 2px 7px 0;
max-width: 220px;
}
.fa-plus {
margin-top: 3px;
float: right;
}
.fa-plus:hover {
opacity: 0.8;
cursor: pointer;
}
#location-detail {
display: none;
}
a#location:focus + #location-detail {
display: block;
}
#media (max-width: 992px) {
.navbar-nav > li,
.navbar-nav > li > a,
.navbar-nav > li > a:link,
.navbar-nav > li > a:visited,
.navbar-nav > li > a:hover {
font-size: 1.05em;
}
}
#media (max-width: 767px) {
.navbar .navbar-brand {
position: absolute;
left: 50%;
margin-left: -110px !important;
display: block;
}
.collapse.navbar-collapse {
background-color: #444;
position: fixed;
min-width: 100%;
min-height: 100%;
font-size: 1.3em;
text-align: center;
padding-top: 20px;
transition-property: all;
transition-duration: 0.5s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
.collapse.navbar-collapse li {
margin-bottom: 15px;
}
}
<div id="main-wrapper">
<div 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 top-bar"></span>
<span class="icon-bar middle-bar"></span>
<span class="icon-bar bottom-bar"></span>
</button>
<!--<img class="logo" src="../images/eclipse-new.png"/> -->
Eclipse Music
</div> <!-- end of navbar-header -->
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<!--<li><span class="glyphicon glyphicon-home"></span>Home</li>-->
<li>Effects</li>
<li>Guitar</li>
<li>Bass</li>
<li>Amps</li>
<li>Lessons</li>
<li class="dropdown">
About<!-- <i class="fa fa-caret-down"></i>-->
<ul class="dropdown-menu">
<li>Directions</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</li>
</ul>
</div> <!-- end of collapse navbar-collapse -->
</div> <!-- end of container -->
</div> <!-- end of navbar navbar-default navbar-fixed-top -->
<div class="article">
<div class="container">
<h2>
Welcome!
</h2>
<br />
</div>
</div> <!-- END of article -->
<footer>
</footer> <!-- END of footer -->
</div> <!-- END of main-wrapper -->
Just add this css in your media query for Xs :
#media (max-width: 767px) {
.navbar .navbar-brand {
position: absolute;
left: 50%;
margin-left: -110px !important;
display: block;
}
.navbar-collapse {
text-align: center;
}
.navbar-collapse li{display:none}
.collapse.navbar-collapse {
background-color: #444;
position: fixed;
min-width: 100%;
min-height: 100%;
font-size: 1.3em;
padding-top: 20px;
transition-property: all;
transition-duration: 0.5s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
.collapse.navbar-collapse li {
display:block;
margin-bottom: 15px;
}
}
Here is a bootply with this change : http://www.bootply.com/BQGSpd2kLt
I could be wrong, but it might be this:
.navbar-toggle {
float: left;
border: none;
margin-top: 10px;
margin-left: 10px;
padding: 4px;}
May want those to be something more like this:
.navbar-toggle {
float: right;
border: none;
position: relative;
left: -50%; //or right 50%
text-align: left;
padding: 4px;}

Close menu item when clicking on another menu element

How can I make other slide-down menus close when clicking on another menu item? Right now all menu items are opening one by one and they can only be closed by clicking on the item again.
Here's a demo: http://bootsnipp.com/snippets/33qKz
And here's the code
function htmlbodyHeightUpdate(){
var height3 = $( window ).height()
var height1 = $('.nav').height()+50
height2 = $('.main').height()
if(height2 > height3){
$('html').height(Math.max(height1,height3,height2)+10);
$('body').height(Math.max(height1,height3,height2)+10);
}
else
{
$('html').height(Math.max(height1,height3,height2));
$('body').height(Math.max(height1,height3,height2));
}
}
$(document).ready(function () {
htmlbodyHeightUpdate()
$( window ).resize(function() {
htmlbodyHeightUpdate()
});
$( window ).scroll(function() {
height2 = $('.main').height()
htmlbodyHeightUpdate()
});
});
/* Adding gvnix styles css - NO COPIAR */
#import 'http://geo-gvnix.rhcloud.com/resources/styles/standard.css';
/* Custom fixed navs */
header.navbar+nav.navbar {
/* margin-top: 20px;same margin-bottom .navbar */
}
.navbar.navbar-default.navbar-fixed-top {
margin-top: 50px;
}
.sidebar.navbar-fixed-top {
margin-top: 100px;
}
#media (min-width: 768px) and (max-width: 998px) {
.navbar.navbar-default.navbar-fixed-top {
margin-top: 100px;
}
.sidebar.navbar-fixed-top {
margin-top: 150px;
}
}
/* Custom navbar default: global*/
.navbar.navbar-default {
background-color: #f8f8f8;
border-color: #e7e7e7;
margin: 0;
border-radius: 0;
}
.navbar.navbar-default .navbar-brand {
color: #666;
text-shadow: none;
min-width: 150px;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #666;
text-shadow: none;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #666;
text-shadow: none;
}
.navbar.navbar-default .navbar-nav > li > a:hover {
color: #acc47f;
}
.navbar.navbar-default .navbar-nav > .active > a {
color: #fff;
background-color: #acc47f;
}
.navbar.navbar-default .navbar-nav > .active > a:hover {
color: #608224;
background-color: #acc47f;
}
.navbar.navbar-default .caret {
border-top-color: #ccc;
border-bottom-color: #ccc;
}
.navbar.navbar-default .caret:hover {
border-top-color: #333;
border-bottom-color: #333;
}
/* Custom sidebar menu */
/*Remove rounded coners*/
nav.sidebar.navbar {
border-radius: 0px;
}
nav.sidebar,
.main {
-webkit-transition: margin 200ms ease-out;
-moz-transition: margin 200ms ease-out;
-o-transition: margin 200ms ease-out;
transition: margin 200ms ease-out;
}
/* Add gap to nav and right windows.*/
.main {
padding: 10px 10px 0 10px;
}
/* .....NavBar: Icon only with coloring/layout.....*/
/*small/medium side display*/
#media (min-width: 768px) {
/*Allow main to be next to Nav*/
.main {
position: absolute;
width: calc(100% - 40px);
/*keeps 100% minus nav size*/
margin-left: 40px;
float: right;
}
/*lets nav bar to be showed on mouseover*/
nav.sidebar:hover + .main {
margin-left: 200px;
}
/*Center Brand*/
nav.sidebar.navbar.sidebar>.container .navbar-brand,
.navbar>.container-fluid .navbar-brand {
margin-left: 0px;
}
/*Center Brand*/
nav.sidebar .navbar-brand,
nav.sidebar .navbar-header {
text-align: center;
width: 100%;
margin-left: 0px;
}
/*Center Icons*/
nav.sidebar a {
padding-right: 13px;
min-width: 100px;
}
/*custom sidebar nav*/
nav.sidebar ul.nav.navbar-nav {
margin: 0;
}
nav.sidebar.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: white;
}
/*adds border top to first nav box */
nav.sidebar .navbar-nav > li:first-child {
border-top: 1px #e5e5e5 solid;
}
/*adds border to bottom nav boxes*/
nav.sidebar .navbar-nav > li {
border-bottom: 1px #e5e5e5 solid;
}
/*adds background on hover*/
nav.sidebar .navbar-nav > li:hover {
color: #fff;
background-color: #43600E;
}
/*removes border last element*/
nav.sidebar .navbar-nav > li.last {
border-bottom: none;
}
/* Colors/style dropdown box*/
nav.sidebar .navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
/*allows nav box to use 100% width*/
nav.sidebar .navbar-collapse,
nav.sidebar .container-fluid {
padding: 0 0px 0 0px;
}
/*colors dropdown box text */
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: #777;
}
/*O quanto o menu irá esconder á esquerda*/
/*gives sidebar width/height*/
nav.sidebar {
width: 200px;
height: 100%;
margin-left: -270px;
float: left;
z-index: 8000;
margin-bottom: 0px;
}
/*give sidebar 100% width;*/
nav.sidebar li {
width: 100%;
}
/* Move nav to full on mouse over*/
nav.sidebar:hover {
margin-left: 0px;
}
/*for hiden things when navbar hidden*/
.forAnimate {
opacity: 0;
}
}
/* .....NavBar: Fully showing nav bar..... */
#media (min-width: 1330px) {
/* Allow main to be next to Nav
.main{
width: calc(100% - 200px); keeps 100% minus nav size
margin-left: 200px;
}
Show all nav
nav.sidebar{
margin-left: 0px;
float: left;
}
Show hidden items on nav
nav.sidebar .forAnimate{
opacity: 1;
} */
}
nav.sidebar .navbar-nav .open .dropdown-menu>li>a:hover,
nav.sidebar .navbar-nav .open .dropdown-menu>li>a:focus {
color: #CCC;
background-color: transparent;
}
nav:hover .forAnimate {
opacity: 1;
}
/*---- FIM SLIDE MENU*/
.nav-side-menu {
overflow: auto;
font-family: verdana;
font-size: 12px;
font-weight: 200;
background-color: #2e353d;
position: fixed;
top: 0px;
width: 300px;
height: 100%;
color: #e1ffff;
}
.nav-side-menu .brand {
background-color: #23282e;
line-height: 50px;
display: block;
text-align: center;
font-size: 14px;
}
.nav-side-menu .toggle-btn {
display: none;
}
.nav-side-menu ul,
.nav-side-menu li {
list-style: none;
padding: 0px;
margin: 0px;
line-height: 35px;
cursor: pointer;
/*
.collapsed{
.arrow:before{
font-family: FontAwesome;
content: "\f053";
display: inline-block;
padding-left:10px;
padding-right: 10px;
vertical-align: middle;
float:right;
}
}
*/
}
.nav-side-menu ul :not(collapsed) .arrow:before,
.nav-side-menu li :not(collapsed) .arrow:before {
font-family: FontAwesome;
content: "\f078";
display: inline-block;
padding-left: 10px;
padding-right: 10px;
vertical-align: middle;
float: right;
}
.nav-side-menu ul .active,
.nav-side-menu li .active {
border-left: 3px solid #d19b3d;
background-color: #4f5b69;
}
.nav-side-menu ul .sub-menu li.active,
.nav-side-menu li .sub-menu li.active {
color: #d19b3d;
}
.nav-side-menu ul .sub-menu li.active a,
.nav-side-menu li .sub-menu li.active a {
color: #d19b3d;
}
.nav-side-menu ul .sub-menu li,
.nav-side-menu li .sub-menu li {
background-color: #181c20;
border: none;
line-height: 28px;
border-bottom: 1px solid #23282e;
margin-left: 0px;
}
.nav-side-menu ul .sub-menu li:hover,
.nav-side-menu li .sub-menu li:hover {
background-color: #020203;
}
.nav-side-menu ul .sub-menu li:before,
.nav-side-menu li .sub-menu li:before {
font-family: FontAwesome;
content: "\f105";
display: inline-block;
padding-left: 10px;
padding-right: 10px;
vertical-align: middle;
}
.nav-side-menu li {
padding-left: 0px;
border-left: 3px solid #2e353d;
border-bottom: 1px solid #23282e;
}
.nav-side-menu li a {
text-decoration: none;
color: #e1ffff;
}
.nav-side-menu li a i {
padding-left: 10px;
width: 20px;
padding-right: 20px;
}
.nav-side-menu li:hover {
border-left: 3px solid #d19b3d;
background-color: #4f5b69;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
#media (max-width: 767px) {
.nav-side-menu {
position: relative;
width: 100%;
margin-bottom: 10px;
}
.nav-side-menu .toggle-btn {
display: block;
cursor: pointer;
position: absolute;
right: 10px;
top: 10px;
z-index: 10 !important;
padding: 3px;
background-color: #ffffff;
color: #000;
width: 40px;
text-align: center;
}
.brand {
text-align: left !important;
font-size: 22px;
padding-left: 20px;
line-height: 50px !important;
}
}
#media (min-width: 767px) {
.nav-side-menu .menu-list .menu-content {
display: block;
}
}
body {
margin: 0px;
padding: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--nav sidebar -->
<aside>
<nav class="navbar navbar-inverse sidebar navbar-fixed-top" role="navigation">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div class="nav-side-menu">
<div class="brand">Brand Logo</div>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
<li>
<a href="#">
<i class="fa fa-dashboard fa-lg"></i> Dashboard
</a>
</li>
<li data-toggle="collapse" data-target="#products" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> UI Elements <i class="fa fa-gift fa-lg btn pull-right" style="margin-top:5px"></i>
</li>
<ul class="sub-menu collapse" id="products">
<li class="active">CSS3 Animation
</li>
<li>General
</li>
<li>Buttons
</li>
<li>Tabs & Accordions
</li>
<li>Typography
</li>
<li>FontAwesome
</li>
<li>Slider
</li>
<li>Panels
</li>
<li>Widgets
</li>
<li>Bootstrap Model
</li>
</ul>
<li data-toggle="collapse" data-target="#service" class="collapsed">
<i class="fa fa-globe fa-lg"></i> Services <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="service">
<li>New Service 1</li>
<li>New Service 2</li>
<li>New Service 3</li>
</ul>
<li data-toggle="collapse" data-target="#new" class="collapsed">
<i class="fa fa-car fa-lg"></i> New <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="new">
<li>New New 1</li>
<li>New New 2</li>
<li>New New 3</li>
</ul>
<li>
<a href="#">
<i class="fa fa-user fa-lg"></i> Profile
</a>
</li>
<li>
<a href="#">
<i class="fa fa-users fa-lg"></i> Users
</a>
</li>
</ul>
</div>
</div>
</nav>
</aside>
<div class="main">
</div>
Your HTML structure is not quite what Bootstrap expects and you won't be able to use the easy way of data-parent attribute on this structure (the items should be divs and have the class panel anyway). Please see documentation for more info if interested. But for your problem and something you can make work directly into your HTML. I added toggle-this class to all the parent menu items which are toggled and added the attribute data-parent="menu-content" to them also. Then I just use this jQuery function to see if there are any menus expanded on click and collapse all the other than the one just clicked like this:
$(document).on('click', '.toggle-this', function(event) {
event.stopPropagation();
var $this = $(this);
var parent = $this.data('parent');
var actives = $('#' + parent).find('[aria-expanded="true"]');
if (actives && actives.length) {
hasData = actives.data('collapse');
actives.collapse('hide');
}
var target = $this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, ''); //strip for ie7
$(target).collapse('toggle');
});
Here's a working JSFiddle: https://jsfiddle.net/thepio/x5j6v5fq/
Your html does not follow the documentation from bootstrap.
The right structure should be something like this:
<ul class="nav navbar-nav">
<li class="active">Dashboard</li>
<li class="dropdown">
UI Elements <span class="caret"></span>
<ul class="dropdown-menu">
<li>CSS3 Animation</li>
<li>General</li>
<li>Buttons</li>
...
</ul>
</li>
...
</ul>
I relize that this would mean you have to re-style some parts of your navigation, but it gives you the functionality that you want.
For more information check bootstraps documentation about navbars
Alternative you can make a little script to change/remove classes on the opened menu items when you click a new one.

Navigation menu can't hide/show (Responsive Design)

Here is the coding what I have provided this one. This is for responsive design. When I click the logo, it didn't want to hide or show.
.toggle-nav {
display: none;
}
.menu {
float: right;
}
.menu ul {
display: inline-block;
}
.menu li {
float: left;
list-style: none;
font-size: 17px;
text-align: right;
}
.menuLink a {
font-size: 20px;
color: #FFF;
margin: 20px;
padding: 10px;
text-decoration: none;
float: left;
font-family: 'alegreya_sansregular';
cursor: pointer;
}
.menuLink a:hover,
.menu .current-item a {
border-bottom: 4px double #FFF;
}
.fixedPosition {
position: fixed !important;
top: 0;
left: 0;
}
#media only screen and (max-width: 820px) {
.menu {
position: relative;
display: inline-block;
}
.menu ul.active {
display: none;
}
.menu ul {
width: 100%;
position: absolute;
top: 90%;
left: -55px;
padding: 10px 18px;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
border-radius: 3px;
background: #cecece;
}
.menu ul:after {
width: 0px;
height: 0px;
position: absolute;
top: 0%;
left: 87px;
content: '';
transform: translate(0%, -100%);
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #cecece;
}
.menu li {
margin: 5px 0px;
float: none;
display: inline-block;
}
.menuLink a {
display: block;
font-size: 15px;
margin: 10px 0;
padding: 5px 0;
float: none;
}
.menuLink a:hover,
.menu .current-item a {
border-bottom: none;
color: #666;
}
.toggle-nav {
padding: 20px;
float: left;
display: inline-block;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
border-radius: 3px;
background: #cecece;
color: #777;
font-size: 20px;
transition: color linear 0.15s;
}
a.toggle-nav {
padding: 10px;
margin: 20px;
}
.toggle-nav:hover,
.toggle-nav.active {
color: #C3c3c3;
border-bottom: none;
position: relative;
}
}
<nav class="menu">
<ul class="menuLink">
<li> <a class="link-nav" data-scroll-nav="0"> HOME </a>
</li>
<li> WORKS
</li>
<li> <a data-scroll-nav="2"> ABOUT </a>
</li>
<li> <a data-scroll-nav="3"> CONTACT </a>
</li>
</ul>
<a class="toggle-nav" href="#">☰</a>
</nav>
Here is JSFIDDLE.
Before I click, the menu is staying there and doesn't want to hide. What I want is the menu has to hide at first before I click the logo. And also the menu can hide back after click the logo when it's showing. Any idea?
just use this jquery
$('.toggle-nav').click(function(){
$(this).parent().find('.menuLink').toggle();
});
FIDDLE
Here is my example with expanding and animated menues.
https://jsfiddle.net/9bn5t0kj/8/
$('.menu-header').on('click', function() {
$(this).next().toggleClass('menu-item-open');
$('.menu-item').not($(this).next()).removeClass('menu-item-open');
});
$(document).on('click', function(e) {
var clickedItem = $(e.target);
if (clickedItem.is($('.menu-header')) || clickedItem.is($('.menu-item'))) {
console.log(clickedItem);
return;
}
$('.menu-item').removeClass('menu-item-open');
});
.menu-item-container {
float: left;
}
.menu-header {
-webkit-user-select: none;
cursor: pointer;
}
.menu-item {
height: 0;
overflow: hidden;
-webkit-transition: height .25s;
}
.menu-item-open {
height: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu">
<div class="menu-item-container">
<div class="menu-header">Open 1</div>
<div class="menu-item">
Hej hopp!<br>
Hej hopp!<br>
Hej hopp!<br>
Hej hopp!<br>
Hej hopp!<br>
</div>
</div>
<div class="menu-item-container">
<div class="menu-header">Open 2</div>
<div class="menu-item">
Hej hopp 2!<br>
Hej hopp 2!<br>
Hej hopp 2!<br>
Hej hopp 2!<br>
Hej hopp 2!<br>
</div>
</div>
You can hide it by default with jQuery .hide() and show it when .toggle-nav is clicked. it's pretty simple.
$(document).ready(function() {
$('.menuLink').hide();
$('.toggle-nav').click(function() {
$('.menuLink').toggle();
});
});
.toggle-nav {
display: none;
}
.menu {
float: right;
}
.menu ul {
display: inline-block;
}
.menu li {
float: left;
list-style: none;
font-size: 17px;
text-align: right;
}
.menuLink a {
font-size: 20px;
color: #FFF;
margin: 20px;
padding: 10px;
text-decoration: none;
float: left;
font-family: 'alegreya_sansregular';
cursor: pointer;
}
.menuLink a:hover,
.menu .current-item a {
border-bottom: 4px double #FFF;
}
.fixedPosition {
position: fixed !important;
top: 0;
left: 0;
}
#media only screen and (max-width: 820px) {
.menu {
position: relative;
display: inline-block;
}
.menu ul.active {
display: none;
}
.menu ul {
width: 100%;
position: absolute;
top: 90%;
left: -55px;
padding: 10px 18px;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
border-radius: 3px;
background: #cecece;
}
.menu ul:after {
width: 0px;
height: 0px;
position: absolute;
top: 0%;
left: 87px;
content: '';
transform: translate(0%, -100%);
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #cecece;
}
.menu li {
margin: 5px 0px;
float: none;
display: inline-block;
}
.menuLink a {
display: block;
font-size: 15px;
margin: 10px 0;
padding: 5px 0;
float: none;
}
.menuLink a:hover,
.menu .current-item a {
border-bottom: none;
color: #666;
}
.toggle-nav {
padding: 20px;
float: left;
display: inline-block;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
border-radius: 3px;
background: #cecece;
color: #777;
font-size: 20px;
transition: color linear 0.15s;
}
a.toggle-nav {
padding: 10px;
margin: 20px;
}
.toggle-nav:hover,
.toggle-nav.active {
color: #C3c3c3;
border-bottom: none;
position: relative;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="menu">
<ul class="menuLink">
<li> <a class="link-nav" data-scroll-nav="0"> HOME </a>
</li>
<li> WORKS
</li>
<li> <a data-scroll-nav="2"> ABOUT </a>
</li>
<li> <a data-scroll-nav="3"> CONTACT </a>
</li>
</ul>
<a class="toggle-nav" href="#">☰</a>
</nav>