How do I make a responsive navigation menu? - html

I am trying to follow this tutorial and I can't get the navigation menu to work. I have also watched this tutorial where the tutor states that by changing the position to static, one can make it responsive and look neat on a mobile device. I am trying to move my submenu more to the right and have it changed back into position absolute of around 150px but my game menu does not work too well...
I also noticed that if I changed the left position to around 200px, then it does work better but this is too far to the left:
* {
margin: 0px;
padding: 0px;
}
body {
font-family: verdana;
background-color: #abc;
padding: 50px;
}
h1 {
text-align: center;
border-bottom: 2px solid #009;
margin-bottom: 50px;
}
/* Rules for navigation menu */
ul#navmenu, ul.sub1 , ul.sub2 {
list-style: none;
font-size: 12px;
}
ul#navmenu li {
width: 250px;
text-align: center;
position: relative; /*This is very important to get sub menu absolutely line up with it */
float: left; /*Get elements side by side */
margin-right: 4px;
}
ul#navmenu a {
text-decoration: none;
display: block;
width: 250px;
height: 25px;
line-height: 25px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
}
ul#navmenu .sub1 a {
margin-top: 5px;
}
ul#navmenu .sub2 a {
margin-left: 10px;
}
ul#navmenu li:hover > a { /* > child selector */
background-color: #cfc;
}
ul#navmenu li:hover a:hover {
background-color: #ff0;
}
ul#navmenu ul.sub1 {
display: none;
position: absolute;
top: 26px;
left: 0px;
}
ul#navmenu ul.sub2 {
display: none;
position: absolute;
top: 0px;
left: 251px;
}
ul#navmenu li:hover .sub1 {
display: block;
}
ul#navmenu .sub1 li:hover .sub2 {
display:block;
}
.darrow {
font-size: 14px;
position: absolute;
top: 5px;
right: 4px;
}
.rarrow {
font-size: 14px;
position: absolute;
top: 8px;
right: 4px;
}
#media screen and (max-width: 600px) {
ul#navmenu li {
width: 250px;
text-align: center;
position: relative; /*This is very important to get sub menu absolutely line up with it */
float: center;
margin-right: 4px;
}
ul#navmenu a {
text-decoration: none;
display: block;
width: 100px;
height: 50px;
line-height: 25px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
}
ul#navmenu .sub1 a {
margin-top: 5px;
}
ul#navmenu .sub2 a {
margin-left: 10px;
}
ul#navmenu ul.sub1 {
display: none;
position: absolute;
left: 150px;
top: -50px;
}
ul#navmenu ul.sub2 {
display: none;
position: static;
}
ul#navmenu li:hover .sub1 {
display: block;
}
ul#navmenu .sub1 li:hover .sub2 {
display:block;
}
.darrow {
display: none;
}
.rarrow {
display: none;
}
}

how to do a responsive navigation menu
Try the following. It makes use of only HTML and CSS.
body {
background: #ccc;
font-family: helvetica, arial, serif;
font-size: 13px;
text-transform: uppercase;
text-align: center;
}
.wrap {
display: inline-block;
-webkit-box-shadow: 0 0 70px #fff;
-moz-box-shadow: 0 0 70px #fff;
box-shadow: 0 0 70px #fff;
margin-top: 40px;
}
/* a little "umph" */
.decor {
background: #6EAF8D;
background: -webkit-linear-gradient(left, #CDEBDB 50%, #6EAF8D 50%);
background: -moz-linear-gradient(left, #CDEBDB 50%, #6EAF8D 50%);
background: -o-linear-gradient(left, #CDEBDB 50%, #6EAF8D 50%);
background: linear-gradient(left, white 50%, #6EAF8D 50%);
background-size: 50px 25%;;
padding: 2px;
display: block;
}
a {
text-decoration: none;
color: #fff;
display: block;
}
ul {
list-style: none;
position: relative;
text-align: left;
}
li {
float: left;
}
/* clear'n floats */
ul:after {
clear: both;
}
ul:before,
ul:after {
content: " ";
display: table;
}
nav {
position: relative;
background: #2B2B2B;
background-image: -webkit-linear-gradient(bottom, #2B2B2B 7%, #333333 100%);
background-image: -moz-linear-gradient(bottom, #2B2B2B 7%, #333333 100%);
background-image: -o-linear-gradient(bottom, #2B2B2B 7%, #333333 100%);
background-image: linear-gradient(bottom, #2B2B2B 7%, #333333 100%);
text-align: center;
letter-spacing: 1px;
text-shadow: 1px 1px 1px #0E0E0E;
-webkit-box-shadow: 2px 2px 3px #888;
-moz-box-shadow: 2px 2px 3px #888;
box-shadow: 2px 2px 3px #888;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
}
/* prime */
ul.primary li a {
display: block;
padding: 20px 30px;
border-right: 1px solid #3D3D3D;
}
ul.primary li:last-child a {
border-right: none;
}
ul.primary li a:hover {
color: #000;
}
/* subs */
ul.sub {
position: absolute;
z-index: 200;
box-shadow: 2px 2px 0 #BEBEBE;
width: 35%;
display:none;
}
ul.sub li {
float: none;
margin: 0;
}
ul.sub li a {
border-bottom: 1px dotted #ccc;
border-right: none;
color: #000;
padding: 15px 30px;
}
ul.sub li:last-child a {
border-bottom: none;
}
ul.sub li a:hover {
color: #000;
background: #eeeeee;
}
/* sub display*/
ul.primary li:hover ul {
display: block;
background: #fff;
}
/* keeps the tab background white */
ul.primary li:hover a {
background: #fff;
color: #666;
text-shadow: none;
}
ul.primary li:hover > a{
color: #000;
}
#media only screen and (max-width: 600px) {
.decor {
padding: 3px;
}
.wrap {
width: 100%;
margin-top: 0px;
}
li {
float: none;
}
ul.primary li:hover a {
background: none;
color: #8B8B8B;
text-shadow: 1px 1px #000;
}
ul.primary li:hover ul {
display: block;
background: #272727;
color: #fff;
}
ul.sub {
display: block;
position: static;
box-shadow: none;
width: 100%;
}
ul.sub li a {
background: #272727;
border: none;
color: #8B8B8B;
}
ul.sub li a:hover {
color: #ccc;
background: none;
}
}
<head>
<meta name="viewport" content="width=device-width">
</head>
<div class="wrap">
<span class="decor"></span>
<nav>
<ul class="primary">
<li>
Dog
<ul class="sub">
<li>Bulldog</li>
<li>Mastiff</li>
<li>Labrador</li>
<li>Mutt</li>
</ul>
</li>
<li>
Cat
<ul class="sub">
<li>Tabby</li>
<li>Black Cat</li>
<li>Wrinkly Cat</li>
</ul>
</li>
<li>
Bird
<ul class="sub">
<li>Humming Bird</li>
<li>Hawk</li>
<li>Crow</li>
</ul>
</li>
<li>
Horse
<ul class="sub">
<li>Brown Horse</li>
<li>Race Horse</li>
<li>Tall Horse</li>
</ul>
</li>
<li>
Burger
<ul class="sub">
<li>Cheesy</li>
<li>More Ketchup</li>
<li>Some Mustard</li>
<li>Extra Butter</li>
</ul>
</li>
</ul>
</nav>
</div>

Related

horizontal float item pushed down in chrome, but not firefox

Why is the last list item in the submenu lower than the rest in Chrome, but aligned in Firefox?
JSFIDDLE with font turned red for visibility
ACTUAL SITE
I have tried everything I can think of with padding, margin, vertical align, last child, etc. Baffled. Thank you.
#hmenuWrapper {
width: 100%;
}
#hmenu, #hmenu ul, #hmenu ul li, #hmenu ul li a {
padding: 0;
margin: 0;
line-height: 1;
font-family: 'Arial', sans-serif;
}
#hmenu:before, #hmenu:after, #hmenu > ul:before, #hmenu > ul:after {
content: '';
display: table;
}
#hmenu:after, #cssmenu > ul:after {
clear: both;
}
#hmenu {
position: relative;
top: 0px;
left: 180px;
zoom: 1;
height: 60px;
width: 740px;
background: url(../media/images/bottom-bg.png) repeat-x center bottom;
border-radius: 2px;
}
#hmenu ul {
background: url(../media/images/nav-bg.png) repeat-x 0px 4px;
height: 69px;
}
#hmenu ul li {
float: left;
list-style: none;
}
#hmenu ul li a {
display: block;
height: 37px;
padding: 17px 14px 0;
margin: 4px 0px 0;
border-radius: 2px 2px 0 0;
text-decoration: none;
font-size: 15px;
color: white;
text-shadow: 0 1px 1px rgba(0, 0, 0, .75);
font-weight: 400;
opacity: .9;
}
#hmenu ul li:first-child a {
margin: 4px 0px 0 0;
}
#hmenu ul li:last-child {
background-color: #168b09;
}
#hmenu ul li a:hover {
background: url(../media/images/colorHover.png) center bottom;
display: block;
height: 37px;
margin-top: 0px;
padding-top: 20px;
color: #616161;
text-shadow: 0 1px 1px rgba(255, 255, 255, .35);
opacity: 1;
}
#hmenu ul li.active a {
background: url(../media/images/color.png) center bottom;
display: block;
height: 37px;
margin-top: 0px;
padding-top: 20px;
color: #616161;
text-shadow: 0 1px 1px rgba(255, 255, 255, .35);
opacity: 1;
}
#nav-wrap {
position: relative;
left: 180px;
top: -3px;
zoom: 1;
height: 40px;
width: 740px;
float: left;
background: url(../media/images/colorinv.png);
}
#nav {
display: inline;
height: 40px;
width: 100%;
}
#nav a:hover {
color: #444444;
text-decoration: none;
}
#nav li:hover {
background: url(../media/images/nav-bginvHover.png);
}
#nav a li:hover {
color: #444444;
}
#nav ui li a {
height: 40px;
width: 185px;
}
.nav-item {
float: left;
height: 40px;
line-height: 40px;
text-align: center;
text-decoration: none;
width: 185px;
list-style-type: none;
color: white;
}
.nav-item a {
height: 40px;
width: 185px;
}
#nav li.nav-sel {
float: left;
height: 40px;
line-height: 40px;
text-align: center;
width: 185px;
list-style-type: none;
color: white;
font-family: 'Arial', sans-serif;
background: url(../media/images/nav-bginv.png);
}
#nav li.nav-sel a {
color: white;
height: 40px;
width: 185px;
line-height: 40px;
}
Remove display: inline from #nav, it's not needed: https://jsfiddle.net/ry5mLkaL/1/
Also, your HTML is invalid starting at line 42. You should not wrap a List Item with an Anchor (or anything). The anchor should be inside of the List Item.
<ul id="nav">
<li class="nav-item">Company Services</li>
<li class="nav-item">Sky Advantages</li>
<li class="nav-item">Customer Recognition</li>
<li class="nav-item">News Releases</li>
</ul>
to
<ul id="nav">
<li class="nav-item">Company Services</li>
<li class="nav-item">Sky Advantages</li>
<li class="nav-item">Customer Recognition</li>
<li class="nav-item">News Releases</li>
</ul>
Because of #nav display:inline.
Set it to display:table-row;
Add #nav{padding-left: 0px} to your CSS, see fiddle: https://jsfiddle.net/zjckk9uL/4/

not able to access submenu on hover when content div is added

I am trying to design a website with a horizantal navigation bar and with a side bar. The problem started when I added a div (content) which is obstructing the submenu
I am adding the code for your reference. Please help me out
html,
body {
height: 100%;
margin: 0;
padding: 0;
-webkit-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
user-select: none;
}
.header {
width: 100%;
height: 60px;
}
/*http://jsfiddle.net/EnKwU/4/*/
.nav {
text-align: center;
width: 85%;
padding: 10px;
margin: 12px 50px 50px 120px;
float: left;
}
.nav ul ul {
display: none;
position: fixed;
}
.nav ul li:hover > ul {
display: block;
}
.nav ul {
background-color: #fff;
margin-top: 10px;
padding: 0 20px;
list-style: none;
position: relative;
display: inline-block;
zoom: 1;
*display: inline;
margin-right: -80px;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 1em;
}
.nav ul li {
float: left;
}
.nav ul li:hover {
border-bottom: 5px solid #339966;
color: #fff;
}
.nav ul li a:hover {
color: #ffffff;
background: #1bbc9b;
}
.nav ul li a {
display: block;
padding: 0.3em 0.8em;
font-family: 'Lato', sans-serif;
font-size: 0.9em;
color: #444;
text-decoration: none;
}
.nav ul ul {
background-color: #fff;
border-radius: 0;
padding: 0;
position: absolute;
top: 100%;
box-shadow: 0 0 9px rgba(0, 0, 0, 0.15);
}
.nav ul ul li {
float: none;
position: relative;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 0.85em;
}
.nav ul ul li a {
padding: 0.4em 1.2em;
color: #000;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 1em;
}
.nav ul ul:before {
content: "";
display: block;
height: 20px;
position: absolute;
top: -20px;
width: 100%;
}
.nav1 {
position: absolute;
left: 25px;
top: 160px;
bottom: 0;
width: 25%;
float: left;
}
.content {
border: 1px solid black;
position: absolute;
left: 26%;
top: 140px;
bottom: 0;
width: 75%;
float: left;
}
/*http://www.9lessons.info/2012/06/simple-drop-down-menu-with-jquery-and.html*/
.dropdown {
color: #555;
margin: 3px -22px 0 0;
width: 143px;
position: relative;
height: 17px;
text-align: left;
float: right;
}
.submenu {
background: #fff;
position: absolute;
top: -12px;
left: -20px;
z-index: 100;
width: 135px;
display: none;
margin-left: 10px;
padding: 40px 0 5px;
border-radius: 6px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
clear: both;
}
.dropdown li a {
color: #555555;
display: block;
font-family: arial;
font-weight: bold;
padding: 6px 15px;
cursor: pointer;
text-decoration: none;
}
.dropdown li a:hover {
background: #155FB0;
color: #FFFFFF;
text-decoration: none;
}
a.account {
font-size: 11px;
line-height: 16px;
color: #555;
position: absolute;
z-index: 110;
display: block;
padding: 11px 0 0 20px;
height: 28px;
width: 121px;
margin: -11px 0 0 -10px;
text-decoration: none;
background: url(icons/arrow.png) 116px 17px no-repeat;
cursor: pointer;
}
.root {
list-style: none;
margin: 0px;
padding: 0px;
font-size: 11px;
padding: 11px 0 0 0px;
border-top: 1px solid #dedede;
}
/* http://codepen.io/daniesy/pen/pfxFi
icons : http://fontawesome.io/
*/
* {
padding: 0;
margin: 0;
font-family: 'Lato', sans-serif;
box-sizing: border-box;
}
.float-right {
float: right;
}
.fa {
font-size: .8em;
line-height: 22px !important;
}
.nav1 {
display: inline-block;
margin: 20px 50px;
}
.nav1 label {
display: block;
width: 250px;
background: #ECF0F1;
padding: 15px 20px;
}
.nav1 ul li {
display: block;
width: 250px;
background: #ECF0F1;
padding: 15px 20px;
}
.nav1 label:hover {
background: #1ABC9C;
color: white;
cursor: pointer;
}
.nav1 ul li:hover {
background: #1ABC9C;
color: white;
cursor: pointer;
}
.nav1 label {
color: #1ABC9C;
border-left: 4px solid #1ABC9C;
border-radius: 0 5px 0 0;
position: relative;
z-index: 2;
}
.nav1 input {
display: none;
}
.nav1 input ~ ul {
position: relative;
visibility: hidden;
opacity: 0;
top: -20px;
z-index: 1;
}
.nav1 input:checked + label {
background: #1ABC9C;
color: white;
}
.nav1 input:checked ~ ul {
visibility: visible;
opacity: 1;
top: 0;
}
.nav1 ul li a {
text-decoration: none;
}
.nav1 ul li:nth-child(1) {
border-left: 4px solid #E74C3C;
}
.nav1 ul li:nth-child(1) .fa {
color: #E74C3C;
}
.nav1 ul li:nth-child(1):hover {
background: #E74C3C;
color: white;
font-weight: bold;
}
.nav1 ul li:nth-child(2) {
border-left: 4px solid #0072B5;
}
.nav1 ul li:nth-child(2) .fa {
color: #0072B5;
}
.nav1 ul li:nth-child(2):hover {
background: #0072B5;
color: white;
font-weight: bold;
}
.nav1 ul li:nth-child(3) {
border-left: 4px solid #EC1559;
}
.nav1 ul li:nth-child(3) .fa {
color: #EC1559;
}
.nav1 ul li:nth-child(3):hover {
background: #EC1559;
color: white;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<link href="menu.css" rel="stylesheet" type="text/css">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.ajax.js"></script>
<script type="text/javascript" src="js/func.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Compliance patch for Microsoft browsers -->
<!--[if lt IE 9]><script src="js/IE9.js"></script><![endif]-->
</head>
<body>
<!---header and side bar for user name and logout menu -starts here -->
<div class="header">
<div class="dropdown">
<a class="account">
<?php $y=$ _SESSION[ 'user']; echo "UserID: $y";?>
</a>
<div class="submenu">
<ul class="root">
<li>Dashboard
</li>
<li>Profile
</li>
<li>Settings
</li>
<li>LogOut
</li>
</ul>
</div>
</div>
</div>
<!--header ended here-->
<!--horizantal navigation bar starts here -->
<div class="nav">
<ul>
<li>Home
</li>
<li>Portfolio
<ul>
<li>Active Directory
<li>HelpDesk
<li>CTS
<li>Exchange/Infra
<li>Others
</ul>
</li>
<li>Downloads
</li>
<li>Blog
</li>
<li>News
</li>
<li>Contact US
</li>
</ul>
</div>
<div class="nav1">
<label for="toggle2" id="kl">Active Directory</label>
<ul class="animate" style="display:none" id="kll">
<li class="animate">Create Domain User
</li>
<li class="animate">Domain Password Reset
</li>
<li class="animate">Domain Joining
</li>
</ul>
</div>
<div class="content">
</div>
</body>
</html>
html,
body {
height: 100%;
margin: 0;
padding: 0;
-webkit-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
user-select: none;
}
.header {
width: 100%;
height: 60px;
}
/*http://jsfiddle.net/EnKwU/4/*/
.nav {
text-align: center;
width: 85%;
padding: 10px;
margin: 12px 50px 50px 120px;
float: left;
}
.nav ul ul {
display: none;
position: fixed;
z-index:999;
}
.nav ul li:hover > ul {
display: block;
}
.nav ul {
background-color: #fff;
margin-top: 10px;
padding: 0 20px;
list-style: none;
position: relative;
display: inline-block;
zoom: 1;
*display: inline;
margin-right: -80px;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 1em;
}
.nav ul li {
float: left;
}
.nav ul li:hover {
border-bottom: 5px solid #339966;
color: #fff;
}
.nav ul li a:hover {
color: #ffffff;
background: #1bbc9b;
}
.nav ul li a {
display: block;
padding: 0.3em 0.8em;
font-family: 'Lato', sans-serif;
font-size: 0.9em;
color: #444;
text-decoration: none;
}
.nav ul ul {
background-color: #fff;
border-radius: 0;
padding: 0;
position: absolute;
top: 100%;
box-shadow: 0 0 9px rgba(0, 0, 0, 0.15);
}
.nav ul ul li {
float: none;
position: relative;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 0.85em;
}
.nav ul ul li a {
padding: 0.4em 1.2em;
color: #000;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 1em;
}
.nav ul ul:before {
content: "";
display: block;
height: 20px;
position: absolute;
top: -20px;
width: 100%;
}
.nav1 {
position: absolute;
left: 25px;
top: 160px;
bottom: 0;
width: 25%;
float: left;
}
.content {
border: 1px solid black;
position: absolute;
left: 26%;
top: 140px;
bottom: 0;
width: 75%;
float: left;
}
/*http://www.9lessons.info/2012/06/simple-drop-down-menu-with-jquery-and.html*/
.dropdown {
color: #555;
margin: 3px -22px 0 0;
width: 143px;
position: relative;
height: 17px;
text-align: left;
float: right;
}
.submenu {
background: #fff;
position: absolute;
top: -12px;
left: -20px;
z-index: 100;
width: 135px;
display: none;
margin-left: 10px;
padding: 40px 0 5px;
border-radius: 6px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
clear: both;
}
.dropdown li a {
color: #555555;
display: block;
font-family: arial;
font-weight: bold;
padding: 6px 15px;
cursor: pointer;
text-decoration: none;
}
.dropdown li a:hover {
background: #155FB0;
color: #FFFFFF;
text-decoration: none;
}
a.account {
font-size: 11px;
line-height: 16px;
color: #555;
position: absolute;
z-index: 110;
display: block;
padding: 11px 0 0 20px;
height: 28px;
width: 121px;
margin: -11px 0 0 -10px;
text-decoration: none;
background: url(icons/arrow.png) 116px 17px no-repeat;
cursor: pointer;
}
.root {
list-style: none;
margin: 0px;
padding: 0px;
font-size: 11px;
padding: 11px 0 0 0px;
border-top: 1px solid #dedede;
}
/* http://codepen.io/daniesy/pen/pfxFi
icons : http://fontawesome.io/
*/
* {
padding: 0;
margin: 0;
font-family: 'Lato', sans-serif;
box-sizing: border-box;
}
.float-right {
float: right;
}
.fa {
font-size: .8em;
line-height: 22px !important;
}
.nav1 {
display: inline-block;
margin: 20px 50px;
}
.nav1 label {
display: block;
width: 250px;
background: #ECF0F1;
padding: 15px 20px;
}
.nav1 ul li {
display: block;
width: 250px;
background: #ECF0F1;
padding: 15px 20px;
}
.nav1 label:hover {
background: #1ABC9C;
color: white;
cursor: pointer;
}
.nav1 ul li:hover {
background: #1ABC9C;
color: white;
cursor: pointer;
}
.nav1 label {
color: #1ABC9C;
border-left: 4px solid #1ABC9C;
border-radius: 0 5px 0 0;
position: relative;
z-index: 2;
}
.nav1 input {
display: none;
}
.nav1 input ~ ul {
position: relative;
visibility: hidden;
opacity: 0;
top: -20px;
z-index: 1;
}
.nav1 input:checked + label {
background: #1ABC9C;
color: white;
}
.nav1 input:checked ~ ul {
visibility: visible;
opacity: 1;
top: 0;
}
.nav1 ul li a {
text-decoration: none;
}
.nav1 ul li:nth-child(1) {
border-left: 4px solid #E74C3C;
}
.nav1 ul li:nth-child(1) .fa {
color: #E74C3C;
}
.nav1 ul li:nth-child(1):hover {
background: #E74C3C;
color: white;
font-weight: bold;
}
.nav1 ul li:nth-child(2) {
border-left: 4px solid #0072B5;
}
.nav1 ul li:nth-child(2) .fa {
color: #0072B5;
}
.nav1 ul li:nth-child(2):hover {
background: #0072B5;
color: white;
font-weight: bold;
}
.nav1 ul li:nth-child(3) {
border-left: 4px solid #EC1559;
}
.nav1 ul li:nth-child(3) .fa {
color: #EC1559;
}
.nav1 ul li:nth-child(3):hover {
background: #EC1559;
color: white;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<link href="menu.css" rel="stylesheet" type="text/css">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.ajax.js"></script>
<script type="text/javascript" src="js/func.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Compliance patch for Microsoft browsers -->
<!--[if lt IE 9]><script src="js/IE9.js"></script><![endif]-->
</head>
<body>
<!---header and side bar for user name and logout menu -starts here -->
<div class="header">
<div class="dropdown">
<a class="account">
<?php $y=$ _SESSION[ 'user']; echo "UserID: $y";?>
</a>
<div class="submenu">
<ul class="root">
<li>Dashboard
</li>
<li>Profile
</li>
<li>Settings
</li>
<li>LogOut
</li>
</ul>
</div>
</div>
</div>
<!--header ended here-->
<!--horizantal navigation bar starts here -->
<div class="nav">
<ul>
<li>Home
</li>
<li>Portfolio
<ul>
<li>Active Directory
<li>HelpDesk
<li>CTS
<li>Exchange/Infra
<li>Others
</ul>
</li>
<li>Downloads
</li>
<li>Blog
</li>
<li>News
</li>
<li>Contact US
</li>
</ul>
</div>
<div class="nav1">
<label for="toggle2" id="kl">Active Directory</label>
<ul class="animate" style="display:none" id="kll">
<li class="animate">Create Domain User
</li>
<li class="animate">Domain Password Reset
</li>
<li class="animate">Domain Joining
</li>
</ul>
</div>
<div class="content">
</div>
</body>
</html>
You simply need to increase the z-index of the submenu, by e.g. adding
.nav ul ul{
z-index:99;
}
The z-index property specifies the z-order of an element and its
descendants. When elements overlap, z-order determines which one
covers the other. An element with a larger z-index generally covers an
element with a lower one.
Although a value of 99 is likely excessive in this case, z-index effectively dictates the layering precedence of the element in question. note that in order to apply, the element will also need a position set (which your sub menu's already have)
Add
.content{
z-index: -100;
}
The content was like becoming an overlay on your dropdown menu item. So the cursor active scope was getting lost.
or add z-index in positive value for the menu

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>

Navigationbar light when the user is on that page

Working on a navigation menu but the question I have is how to make the menu buttom light green when I am on the site i pressed so I can see that I am inside Dagvakt for example ?
The menu only light green when the mouse is over it also should light when the person is in that site. Jsfiddle: http://jsfiddle.net/EkLPG/
Html:
<ul id="nav">
<li><img src="images/home.png" /> Forside
</li>
<li><span><img src="images/temperatur.png" /> Måling</span>
</li>
<li><span><img src="images/sol.png" /> Dagvakt</span>
</li>
<li><img src="images/kveld.png" /> Kveldsvakt
</li>
<li><img src="images/vaske.png" /> Kontroll CM
</li>
<li><img src="images/søk.png" /> Søk
</li>
<li><img src="images/top2.png" /> Statistikk
</li>
<li><img src="images/top3.png" /> Rapport
</li>
</ul>
Css
ul#nav {
width: 1050px;
float: right;
font-family: Trebuchet MS, sans-serif;
font-size: 0;
padding: 5px 5px 5px 0;
background: -moz-linear-gradient(#f5f5f5, #c4c4c4); /* FF 3.6+ */
background: -ms-linear-gradient(#f5f5f5, #c4c4c4); /* IE10 */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f5f5f5), color-stop(100%, #c4c4c4)); /* Safari 4+, Chrome 2+ */
background: -webkit-linear-gradient(#f5f5f5, #c4c4c4); /* Safari 5.1+, Chrome 10+ */
background: -o-linear-gradient(#f5f5f5, #c4c4c4); /* Opera 11.10 */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f5f5f5', endColorstr='#c4c4c4'); /* IE6 & IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#f5f5f5', endColorstr='#c4c4c4')"; /* IE8+ */
background: linear-gradient(#F2F2F2, f5f5f5); /* the standard - Farge */
}
ul#nav, ul#nav ul {
list-style: none;
margin: 10px 0px 0px 0px;
}
ul#nav, ul#nav .subs {
background-color: #444;
border: 0px solid #454545; /* Border */
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px;
}
ul#nav .subs {
background-color: #fff;
border: 2px solid #222;
display: none;
float: left;
left: 0;
padding: 0 6px 6px;
position: absolute;
top: 100%;
width: 300px;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
}
ul#nav li:hover>* {
display: block;
}
ul#nav li:hover {
position: relative;
}
ul#nav ul .subs {
left: 100%;
position: absolute;
top: 0;
}
ul#nav ul {
padding: 0 5px 5px;
}
ul#nav .col {
float: left;
width: 50%;
}
ul#nav li {
display: block;
float: left;
font-size: 0;
white-space: nowrap;
}
ul#nav>li, ul#nav li {
margin: 0 0 0 5px;
}
ul#nav ul>li {
margin: 5px 0 0;
}
ul#nav a:active, ul#nav a:focus {
outline-style: none;
}
ul#nav a {
border-style: none;
border-width: 0;
color: #181818;
cursor: pointer;
display: block;
font-size: 13px;
font-weight: bold;
padding: 8px 10px;
text-align: left;
text-decoration: none;
text-shadow: #fff 0 1px 1px;
vertical-align: middle;
}
ul#nav ul li {
float: none;
margin: 6px 0 0;
}
ul#nav ul a {
background-color: #fff;
border-color: #efefef;
border-style: solid;
border-width: 0 0 1px;
color: #000;
font-size: 11px;
padding: 4px;
text-align: left;
text-decoration: none;
text-shadow: #fff 0 0 0;
border-radius: 0;
-moz-border-radius: 0;
-webkit-border-radius: 0;
}
ul#nav li:hover>a {
border-style: none;
color: #fff;
font-size: 13px;
font-weight: bold;
text-decoration: none;
text-shadow: #181818 0 1px 1px;
}
ul#nav img {
border: none;
margin-right: 8px;
vertical-align: middle;
}
ul#nav span {
background-position: right center;
background-repeat: no-repeat;
display: block;
overflow: visible;
padding-right: 0;
}
ul#nav ul li:hover>a {
border-color: #444;
border-style: solid;
color: #444;
font-size: 11px;
text-decoration: none;
text-shadow: #fff 0 0 0;
}
ul#nav > li >a {
background-color: transpa;
height: 25px;
line-height: 25px;
border-radius: 11px;
-moz-border-radius: 11px;
-webkit-border-radius: 11px;
}
ul#nav > li:hover > a {
background-color: #009900;
line-height: 25px;
}
HTML
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">profile</li>
<li>Contact</li>
</ul>
</div>
CSS
ul
{
list-style-type:none;
width:500px;
}
li
{
float:left;
display:inline-block;
text-align:center;
width:100px;
background-color:#003366;
padding:10px;
}
a
{
color:white;
text-decoration:none;
}
li.active {
background-color:red;
text-transform:uppercase;
}
li.active a{
color:white;
text-transform:uppercase;
}
Jquery:
$('li').on('click', function(){
$('li').removeClass('active');
$(this).toggleClass('active');
})
Fiddle
Demo
Your's Working Fiddle

Vertical menu - submenu not popping out

I am new to CSS and I am trying to pop up a sub menu in my vertical menu, but it is not doing it... Please see my CSS and HTML below:
.glossymenu{
list-style-type: none;
margin: 5px 0;
padding: 0;
width: 130px;
border: 1px solid #9A9A9A;
border-bottom-width: 0;
position: relative;
top: 15px;
}
.glossymenu li a{
background: white url(../images/glossyback.gif) repeat-x bottom left;
font: bold 11px/1.5em Verdana;
font-size: 120%;
color: white;
display: block;
width: auto;
padding: 3px 0;
padding-left: 10px;
text-decoration: none;
}
// IE only. Actual menu width minus left padding of A element (10px)
* html .glossymenu li a{
width: 130px;
}
.glossymenu li a:visited, .glossymenu li a:active{
color: white;
}
.glossymenu li a:hover{
background-image: url(../images/glossyback2.gif);
}
ul.sub-level {
display: none;
}
li:hover .sub-level {
background: #999;
border: #fff solid;
border-width: 1px;
display: block;
position: absolute;
left: 100px;
}
ul.sub-level li {
border: none;
float: left;
width: 150px;
}
and my HTML:
<div id="side">
<ul class="glossymenu">
<li>MENU</li>
<ul class="sub-level">
<li><span>Appetizer</span></li>
<li><span>Beverages</span></li>
<li><span>Desserts</span></li>
</ul>
<li>LOCATIONS</li>
<li>HOURS</li>
</ul>
</div>
The submenu element should be inside one of the li elements.
Check this out.
HTML
<div id="side">
<ul class="glossymenu">
<li>MENU
<ul class="sub-level">
<li><span>Appetizer</span></li>
<li><span>Beverages</span></li>
<li><span>Desserts</span></li>
</ul>
</li>
<li>LOCATIONS</li>
<li>HOURS</li>
</ul>
</div>
CSS
.glossymenu{
list-style-type: none;
margin: 5px 0;
padding: 0;
width: 130px;
border: 1px solid #9A9A9A;
border-bottom-width: 0;
position:relative;
top:15px;
}
.glossymenu li a{
background: white url(../images/glossyback.gif) repeat-x bottom left;
font: bold 11px/1.5em Verdana;
font-size:120%;
color: white;
display: block;
width: auto;
padding: 3px 0;
padding-left: 10px;
text-decoration: none;
}
* html .glossymenu li a{ /*IE only. Actual menu width minus left padding of A element (10px) */
width: 130px;
}
.glossymenu li a:visited, .glossymenu li a:active{
color: white;
}
.glossymenu li a:hover{
background-image: url(../images/glossyback2.gif);
}
ul.sub-level {
display: none;
}
.glossymenu li:hover > .sub-level {
background: #999;
border: #fff solid;
border-width: 1px;
display: block;
position: absolute;
left: 100px;
}
ul.sub-level li {
border: none;
float:left;
width:150px;
}