Dropdown nav pushing menu down - html

Currently having a bit of a nightmare with my dropdown menu. When "hovering" over a menu item to view a submenu, the rest of my menu bar is being pushed down.
I have taken the hover out at the moment whilst debugging. Any advice would be great!
https://codepen.io/bradleyr/pen/JjGKZpB
/* CSS: */
.nav-switch {
display: none;
}
.main-menu {
text-align: center;
}
.main-menu ul {
list-style: none;
/* changes from here on */
position: relative;
/* text-align: center; */
}
.main-menu ul li {
display: inline-block;
z-index: 100;
}
.main-menu ul li a {
display: block;
text-transform: uppercase;
font-size: 14px;
color: #fff;
padding: 15px;
margin-left: 20px;
margin-right: 20px;
position: relative;
}
.main-menu ul li img {
height: 7vh;
padding-left: 2vw;
padding-right: 2vw;
}
.main-menu ul li a:after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 1px;
background: #fff;
content: '';
opacity: 0;
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
transition: height 0.3s, opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.main-menu ul li a:hover:after {
height: 3px;
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.main-menu ul li ul {
display: block;
position: relative;
}
.main-menu ul li ul li {
display: block;
/* float: left; */
}
.main-menu ul li ul li a {
font-size: 13px;
width: auto;
min-width: 100px;
/* margin-left: 20px;
margin-right: 20px; */
/* top | right | bottom | left */
}
.main-menu .noLine:hover:after {
opacity: 0;
}
<!-- HTML: -->
<div class="nav-switch">
<i class="fa fa-bars"></i>
</div>
<nav class="main-menu">
<ul>
<li>Who We Are
<li>
What We Do
<ul class="dropdown">
<li>Brand Pop Ups</li>
<li>Weddings</li>
<li>Corporate Events</li>
<li>Festivals</li>
</ul>
</li>
<li>
How We Do It
<ul class="dropdown">
<li>Lighting</li>
<li>Sound</li>
<li>Video</li>
<li>Concept Design</li>
</ul>
</li>
<li>
<img src="/img/logo.svg" class="logoFlashB">
</li>
<!--<li>Venues</li>-->
<li>Case Studies</li>
<li><a href="#">Hire Stock
<li>Contact Us </li>
</ul>
</nav>
Many Thanks,
Brad!!
Example Images...
Broken
How it's supposed to look

Add flex configuration to your .main-menu ul to configure your desire output.
.main-menu ul {
list-style: none;
/* changes from here on */
position: relative;
/* text-align: center; */
display: flex; /* Add this line*/
justify-content: center; /* Add this line */
}
body {
background: black;
}
.nav-switch {
display: none;
}
.main-menu {
text-align: center;
}
.main-menu ul {
list-style: none;
/* changes from here on */
position: relative;
/* text-align: center; */
display: flex; /* Add this line*/
justify-content: center; /* Add this line */
}
.main-menu ul li {
display: inline-block;
z-index: 100;
}
.main-menu ul li a {
display: block;
text-transform: uppercase;
font-size: 14px;
color: #fff;
padding: 15px;
margin-left: 20px;
margin-right: 20px;
position: relative;
}
.main-menu ul li img {
height: 7vh;
padding-left: 2vw;
padding-right: 2vw;
}
.main-menu ul li a:after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 1px;
background: #fff;
content: '';
opacity: 0;
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
transition: height 0.3s, opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.main-menu ul li a:hover:after {
height: 3px;
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.main-menu ul li ul {
display: block;
position: relative;
}
.main-menu ul li ul li {
display: block;
/* float: left; */
}
.main-menu ul li ul li a {
font-size: 13px;
width: auto;
min-width: 100px;
/* margin-left: 20px;
margin-right: 20px; */
/* top | right | bottom | left */
}
.main-menu .noLine:hover:after {
opacity: 0;
}
<div class="nav-switch">
<i class="fa fa-bars"></i>
</div>
<nav class="main-menu">
<ul>
<li>Who We Are
<li>
What We Do
<ul class="dropdown">
<li>Brand Pop Ups</li>
<li>Weddings</li>
<li>Corporate Events</li>
<li>Festivals</li>
</ul>
</li>
<li>
How We Do It
<ul class="dropdown">
<li>Lighting</li>
<li>Sound</li>
<li>Video</li>
<li>Concept Design</li>
</ul>
</li>
<li>
<img src="/img/logo.svg" class="logoFlashB">
</li>
<!--<li>Venues</li>-->
<li>Case Studies</li>
<li><a href="#">Hire Stock
<li>Contact Us </li>
</ul>
</nav>

Related

Show child on parent hover instead of on parent OR child hover

I've created a simple dropdown menu that scales and fades in whenever I hover over the parent list item, "Services". Everything works as it should except for when I hover over the child element (dropdown menu) which also makes it appear. I understand that simply hiding it with opacity will not prevent a user from hovering over it but it allows for the 0.4s transition to take effect. If I were to hide it with display:none or visibility:hidden, the transition becomes instant. I'm considering using jQuery to solve this but was wondering if there is a solution based purely in CSS.
JSFiddle
* {
margin: 0;
padding: 0;
font-family: Montserrat;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
nav {
background-color: white;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
}
nav > ul > li {
display: inline-block;
position: relative;
height: 60px;
cursor: pointer;
}
nav a {
color: rgba(165,175,185,1);
}
nav > ul > li > a {
padding: 0 20px;
height: 100%;
line-height: 60px;
}
nav > ul > li:hover > a {
color: rgba(105,115,125,1);
}
nav > ul > li:first-of-type {
margin-right: auto;
}
.services-list-container {
position: absolute;
width: 200px;
top: 100%;
height: auto;
opacity: 0;
transform: rotateX(-20deg) scale(0.9,0.9);
transform-origin: 0 0;
transition: transform 0.4s ease, opacity 0.4s ease;
}
.services-list-container ul {
background-color: white;
box-shadow: 0 6px 16px rgba(40, 40, 90, 0.15);
position: relative;
margin-top: 30px;
}
.services-list-container a {
padding: 20px;
display: block;
}
.services-list-container a:hover {
padding: 20px;
display: block;
background-color: rgba(235,240,245,1);
}
.hover:hover .services-list-container {
transform: rotateX(0deg) scale(1,1);
opacity: 1;
transition: transform 0.4s ease, opacity 0.4s ease;
}
<nav>
<ul>
<li>
[Logo]
</li>
<li>
About
</li>
<li class="hover">
Services
<div class="services-list-container">
<ul>
<li>
Information
</li>
<li>
Technology
</li>
<li>
Training
</li>
<li>
Project Support
</li>
</ul>
</div>
</li>
<li>
News
</li>
<li>
Jobs
</li>
<li>
Contact
</li>
</ul>
</nav>
It's not that you are hovering over the child element, it's that your list elements are so tall from the height:60px that when you hover under the words, it's still going over the li element.
If you are targeting supporting browsers you can use pointer-events to prevent the submenu from causing a hover mouse event
Give your element pointer-events:none to disable
.services-list-container {
pointer-events:none;
position: absolute;
width: 200px;
top: 100%;
height: auto;
opacity: 0;
transform: rotateX(-20deg) scale(0.9,0.9);
transform-origin: 0 0;
transition: transform 0.4s ease, opacity 0.4s ease;
}
Then to make sure you can still enter the submenu, reset pointer-events while your .hover elements are hovered
.hover:hover .services-list-container {
pointer-events:all;
transform: rotateX(0deg) scale(1,1);
opacity: 1;
transition: transform 0.4s ease, opacity 0.4s ease;
}
Demo
* {
margin: 0;
padding: 0;
font-family: Montserrat;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
nav {
background-color: white;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
}
nav > ul > li {
display: inline-block;
position: relative;
height: 60px;
cursor: pointer;
}
nav a {
color: rgba(165,175,185,1);
}
nav > ul > li > a {
padding: 0 20px;
height: 100%;
line-height: 60px;
}
nav > ul > li:hover > a {
color: rgba(105,115,125,1);
}
nav > ul > li:first-of-type {
margin-right: auto;
}
.services-list-container {
pointer-events:none;
position: absolute;
width: 200px;
top: 100%;
height: auto;
opacity: 0;
transform: rotateX(-20deg) scale(0.9,0.9);
transform-origin: 0 0;
transition: transform 0.4s ease, opacity 0.4s ease;
}
.services-list-container ul {
background-color: white;
box-shadow: 0 6px 16px rgba(40, 40, 90, 0.15);
position: relative;
margin-top: 30px;
}
.services-list-container a {
padding: 20px;
display: block;
}
.services-list-container a:hover {
padding: 20px;
display: block;
background-color: rgba(235,240,245,1);
}
.hover:hover .services-list-container {
pointer-events:all;
transform: rotateX(0deg) scale(1,1);
opacity: 1;
transition: transform 0.4s ease, opacity 0.4s ease;
}
<nav>
<ul>
<li>
[Logo]
</li>
<li>
About
</li>
<li class="hover">
Services
<div class="services-list-container">
<ul>
<li>
Information
</li>
<li>
Technology
</li>
<li>
Training
</li>
<li>
Project Support
</li>
</ul>
</div>
</li>
<li>
News
</li>
<li>
Jobs
</li>
<li>
Contact
</li>
</ul>
</nav>
A combination of visibility:hidden; with the opacity changes helps you to keep that animation while still preventing it from triggering outside of the intended menu area:
https://jsfiddle.net/4wg4sbqy/
CSS:
* {
margin: 0;
padding: 0;
font-family: Montserrat;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
nav {
background-color: white;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
}
nav > ul > li {
display: inline-block;
position: relative;
height: 60px;
cursor: pointer;
}
nav a {
color: rgba(165,175,185,1);
}
nav > ul > li > a {
padding: 0 20px;
height: 100%;
line-height: 60px;
}
nav > ul > li:hover > a {
color: rgba(105,115,125,1);
}
nav > ul > li:first-of-type {
margin-right: auto;
}
.services-list-container {
position: absolute;
width: 200px;
top: 100%;
height: auto;
opacity: 0;
visibility: hidden;
transform: rotateX(-20deg) scale(0.9,0.9);
transform-origin: 0 0;
transition: transform 0.4s ease, opacity 0.4s ease;
}
.services-list-container ul {
background-color: white;
box-shadow: 0 6px 16px rgba(40, 40, 90, 0.15);
position: relative;
margin-top: 30px;
}
.services-list-container a {
padding: 20px;
display: block;
}
.services-list-container a:hover {
padding: 20px;
display: block;
background-color: rgba(235,240,245,1);
}
.hover:hover .services-list-container {
visibility: visible;
transform: rotateX(0deg) scale(1,1);
opacity: 1;
transition: transform 0.4s ease, opacity 0.4s ease;
}
HTML:
<nav>
<ul>
<li>
[Logo]
</li>
<li>
About
</li>
<li class="hover">
Services
<div class="services-list-container">
<ul>
<li>
Information
</li>
<li>
Technology
</li>
<li>
Training
</li>
<li>
Project Support
</li>
</ul>
</div>
</li>
<li>
News
</li>
<li>
Jobs
</li>
<li>
Contact
</li>
</ul>
</nav>
Please check if this is what you want. Submenu is hidden until the hover takes place.
* {
margin: 0;
padding: 0;
font-family: Montserrat;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
nav {
background-color: white;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
}
nav>ul>li {
display: inline-block;
position: relative;
height: 60px;
cursor: pointer;
}
nav a {
color: rgba(165, 175, 185, 1);
}
nav>ul>li>a {
padding: 0 20px;
line-height: 60px;
}
nav>ul>li:hover>a {
color: rgba(105, 115, 125, 1);
}
nav>ul>li:hover .services-list-container {
display: inline-block;
}
nav>ul>li:first-of-type {
margin-right: auto;
}
.services-list-container {
visibility: hidden;
z-index: -1;
position: absolute;
width: 200px;
top: 100%;
opacity: 0;
transition: opacity .4s ease;
}
.services-list-container ul {
background-color: white;
box-shadow: 0 6px 16px rgba(40, 40, 90, 0.15);
position: relative;
}
.services-list-container a {
padding: 20px;
display: block;
}
.services-list-container a:hover {
background-color: rgba(235, 240, 245, 1);
}
.hover:hover .services-list-container {
z-index: 0;
visibility: visible;
opacity: 1;
}
<nav>
<ul>
<li>
[Logo]
</li>
<li>
About
</li>
<li class="hover">
Services
<div class="services-list-container">
<ul>
<li>
Information
</li>
<li>
Technology
</li>
<li>
Training
</li>
<li>
Project Support
</li>
</ul>
</div>
</li>
<li>
News
</li>
<li>
Jobs
</li>
<li>
Contact
</li>
</ul>

How to make a navigation menu item with symmetrical background

I'm trying to get the background to each nav link fixed. I want it to be uniform behind each link, meaning equal on both left and right side.
Link to the actual webpage.
See the code below the picture.
Thanks.
<div class="top-nav">
<span class="menu"><img src="images/menu.png" alt=""></span>
<ul class="nav1" style="margin-top: .5em;">
<li class="hvr-sweep-to-bottom active">Home
</li>
<li class="hvr-sweep-to-bottom">Fleet Management
<ul class="level_1">
<li>Basic
</li>
<li>Basic Plus
</li>
<li>Ultra
</li>
<li>Ultra Plus
</li>
</ul>
</li>
<li class="hvr-sweep-to-bottom">Broker Agency
</li>
<li class="hvr-sweep-to-bottom">Maintenance
</li>
<li class="hvr-sweep-to-bottom">Drivers
</li>
<li class="hvr-sweep-to-bottom">Contact
</li>
<div class="clearfix"></div>
</ul>
And the CSS
.top-nav {
float: right;
width: 80%;
position: absolute;
left: 27%;
top: 20%;
}
.top-nav ul {
padding: 0;
margin: 0;
}
.top-nav ul li {
display: inline-block;
margin-right: .4em;
float: left;
position: relative;
}
.top-nav ul li.active {
background: #bb1e10;
}
.top-nav ul li a {
color: #FFF;
font-size: 18px;
margin-right: .4em;
float: left;
padding: 1em 0em 1em 1.4em;
text-align: center;
width: 79%;
}
.top-nav ul li a i {
display: block;
margin-top: 1em;
color: #FFF;
font-size: 11px;
font-style: italic;
}
.top-nav ul ul {
display: none;
left: 0;
float: left;
position: relative;
}
.top-nav ul ul li {
float: none;
width: 200px;
z-index: 1;
}
.top-nav ul ul li a {
padding: 5px 5px;
}
.top-nav ul li:hover > ul {
display: block;
}
/* Sweep To Bottom */
.hvr-sweep-to-bottom {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
-o-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
-o-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
-ms-osx-font-smoothing: grayscale;
-o-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
-o-transition-property: color;
-moz-transition-property: color;
-ms-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
-moz-transition-duration: 0.3s;
-ms-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-sweep-to-bottom:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #bb1e10;
-webkit-transform: scaleY(0);
-o-transform: scaleY(0);
-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
transform: scaleY(0);
-webkit-transform-origin: 50% 0;
-o-transform-origin: 50% 0;
-moz-transform-origin: 50% 0;
-ms-transform-origin: 50% 0;
transform-origin: 50% 0;
-webkit-transition-property: transform;
-o-transition-property: transform;
-moz-transition-property: transform;
-ms-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
-moz-transition-duration: 0.3s;
-ms-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
-o-transition-timing-function: ease-out;
-moz-transition-timing-function: ease-out;
-ms-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-sweep-to-bottom:hover,
.hvr-sweep-to-bottom:focus,
.hvr-sweep-to-bottom:active {
color: white;
}
.hvr-sweep-to-bottom:hover:before,
.hvr-sweep-to-bottom:focus:before,
.hvr-sweep-to-bottom:active:before {
-webkit-transform: scaleY(1);
transform: scaleY(1);
}
/*---*/
You have added some JavaScript as well (for animations and swipe downs). I was able to mimic something, which doesn't have animations, but works as expected. Have a look here in the full screen:
* {
margin: 0;
padding: 0;
list-style: none;
box-sizing: border-box;
font-family: 'Segoe UI';
}
a {
text-decoration: none;
}
.nav {
display: block;
}
.nav > li {
display: inline-block;
position: relative;
}
.nav > li:hover,
.nav > li.active {
background-color: #f00;
color: #fff;
}
.nav a {
display: block;
padding: 10px;
color: inherit;
}
.nav ul {
display: none;
position: absolute;
left: 0;
right: 0;
background-color: #f00;
color: #fff;
}
.nav > li:hover ul {
display: block;
}
<ul class="nav">
<li class="hvr-sweep-to-bottom active">
Home
</li>
<li class="hvr-sweep-to-bottom">
Fleet Management
<ul>
<li>Basic</li>
<li>Basic Plus</li>
<li>Ultra</li>
<li>Ultra Plus</li>
</ul>
</li>
<li class="hvr-sweep-to-bottom">
Broker Agency
</li>
<li class="hvr-sweep-to-bottom">
Maintenance
</li>
<li class="hvr-sweep-to-bottom">
Drivers
</li>
<li class="hvr-sweep-to-bottom">
Contact
</li>
</ul>
Update
To fix your issue, please add this to the bottom of the style.css:
.nav {
display: block;
margin: 25px;
float: left;
}
.nav > li {
display: inline-block;
position: relative;
}
.nav > li:hover,
.nav > li.active {
background-color: #f00;
color: #fff;
}
.nav a {
display: block;
padding: 10px;
color: #fff;
}
.nav ul {
display: none;
position: absolute;
left: 0;
right: 0;
background-color: #f00;
color: #fff;
z-index: 1;
}
.nav > li:hover ul {
display: block;
}
So this gives an output like this:

DropDown-Menu should stay opend after onClick

My Homepage-Menu-Point "Software" should stay opened if you click on it!
See on my Test-Homepage!
I've tested to add "li:focus" and "li:active" to my lowermost CSS-Tag, but nothing worked. I also tried it with jQuery, without success!
The HTML-Code:
<nav id="cNav">
<div class="Nav">
<ul>
<li>G</li>
<li>Home</li>
<li>Software
<ul>
<li>Android</li>
<li>Windows</li>
</ul>
</li>
<li>Über</li>
</ul>
</div>
</nav>
The CSS-Code:
#cNav {
background-color: rgb(5, 90, 160);
margin: 0;
padding: 0;
width: 100%;
}
.Nav {
font-weight: bold;
font-size: 22pt;
margin: 0;
padding: 0;
}
.Nav ul {
padding: 0;
margin-top: 0;
margin-bottom: 0;
position: relative;
width: 100%;
text-align: center;
}
.Nav ul li {
display: inline-block;
position: relative;
padding-left: 2em;
padding-right: 2em;
padding-top: 0.4em;
padding-bottom: 0.4em;
}
.Nav ul li a {
outline: 0;
color: white;
position: relative;
text-decoration: none;
transition: color 0.3s;
}
.Nav ul li a::after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 4px;
background: white;
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
transform: translateY(10px);
margin: 0;
}
.Nav ul li a:hover::after {
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.Nav ul ul {
display: none;
white-space: nowrap;
position: absolute;
text-align: center;
top: 100%;
margin-left: -5.3em;
}
.Nav ul ul li {
background-color: rgb(5, 90, 160);
border-top: medium solid rgba(0,115,209,1.00);
margin-right: -1em;
}
.Nav ul li:hover > ul {
display: block;
}
If you want your Homepage-Menu-Point "Software" staying opened if you click on it, and you want to use jQuery, this might be a possible solution:
Add an id to the li with software:
<li id="software">Software
Then you can use this to set the css display property of the ul to block:
$(document).ready(function() {
$("#software ul").click(function() {
$(this).css("display", "block");
});
});
Snippet:
$(document).ready(function() {
$("#software ul").click(function() {
$(this).css("display", "block");
});
});
#cNav {
background-color: rgb(5, 90, 160);
margin: 0;
padding: 0;
width: 100%;
}
.Nav {
font-weight: bold;
font-size: 22pt;
margin: 0;
padding: 0;
}
.Nav ul {
padding: 0;
margin-top: 0;
margin-bottom: 0;
position: relative;
width: 100%;
text-align: center;
}
.Nav ul li {
display: inline-block;
position: relative;
padding-left: 2em;
padding-right: 2em;
padding-top: 0.4em;
padding-bottom: 0.4em;
}
.Nav ul li a {
outline: 0;
color: white;
position: relative;
text-decoration: none;
transition: color 0.3s;
}
.Nav ul li a::after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 4px;
background: white;
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
transform: translateY(10px);
margin: 0;
}
.Nav ul li a:hover::after {
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.Nav ul ul {
display: none;
white-space: nowrap;
position: absolute;
text-align: center;
top: 100%;
margin-left: -5.3em;
}
.Nav ul ul li {
background-color: rgb(5, 90, 160);
border-top: medium solid rgba(0,115,209,1.00);
margin-right: -1em;
}
.Nav ul li:hover > ul {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="cNav">
<div class="Nav">
<ul>
<li>G</li>
<li>Home</li>
<li id="software">Software
<ul>
<li>Android</li>
<li>Windows</li>
</ul>
</li>
<li>Über</li>
</ul>
</div>
</nav>

CSS multilvel menu issue at third level

I've made a three level menu in HTML and CSS.
The menu works until the third level (under products). The third ul sub-menu isn't displaying properly. It's being aligned improperly. I want it to get out of it's parent menu and be positioned at the right.
Here is a jsfiddle with my code.
I've changed some postions of ul, li but they don't seem to be working for me.
CSS, HTML in the fiddle:
#nav,#nav ul {
list-style: none outside none;
margin: 0;
padding: 0;
}
#menucon {
width:100%;
background-color:#222;
}
#nav {
clear: both;
font-size: 12px;
height: 42px;
}
#nav ul {
background-color: #222;
background-color: rgba(34,34,34,0.70);
border:1px solid #222;
border-radius: 0 5px 5px 5px;
border-width: 0 1px 1px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
left: -9999px;
overflow: hidden;
position: absolute;
top: -9999px;
-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
-o-transform: scaleY(0);
-webkit-transform: scaleY(0);
transform: scaleY(0);
}
#nav ul.sec { z-index: 2; }
#nav ul.third { z-index: 3; border:2px solid red; }
#nav li {
background: url('menu_line.png') no-repeat scroll right 5px transparent;
float: left;
position: relative;
}
#nav li a {
color: #FFFFFF;
display: block;
float: left;
font-weight: normal;
height: 27px;
padding: 14px 30px 0;
position: relative;
text-decoration: none;
text-shadow: 1px 1px 1px #000000;
}
#nav ul.subs li a {
color: #FFFFFF;
display: block;
float: left;
font-weight: normal;
height: 27px;
padding: 13px 25px 0;
position: relative;
width:178px;
text-decoration: none;
text-shadow: 1px 1px 1px #000000;
}
#nav li:hover > a {
color: #00B4FF;
}
#nav li:hover, #nav a:focus, #nav a:hover, #nav a:active {
background: none repeat scroll 0 0 #121212;
outline: 0 none;
}
#nav li:hover ul.subs.sec {
left: 0;
top: 41px;
-moz-transform: scaleY(1);
-ms-transform: scaleY(1);
-o-transform: scaleY(1);
-webkit-transform: scaleY(1);
transform: scaleY(1);
position:absolute;
}
#nav li:hover ul.subs.third {
left: 60px; /* test */
top: 41px;
-moz-transform: scaleY(1);
-ms-transform: scaleY(1);
-o-transform: scaleY(1);
-webkit-transform: scaleY(1);
transform: scaleY(1);
position:absolute;
}
#nav ul li {
background: none;
width: 100%;
}
#nav ul li.sec {position:relative;}
#nav ul li a {
float: none;
}
#nav ul li:hover > a {
background-color: #121212;
color: #00B4FF;
}
#lavalamp {
background: url('lavalamp.png') no-repeat scroll 0 0 transparent;
height: 16px;
left: 32px;
position: absolute;
top: 0px;
width: 64px;
-moz-transition: all 400ms ease-out ;
-ms-transition: all 400ms ease-out ;
-o-transition: all 400ms ease-out ;
-webkit-transition: all 400ms ease-out ;
transition: all 400ms ease-out ;
}
#lavalamp:hover {
-moz-transition-duration: 4500s;
-ms-transition-duration: 4500s;
-o-transition-duration: 4500s;
-webkit-transition-duration: 4500s;
transition-duration: 4500s;
}
#nav li:nth-of-type(1):hover ~ #lavalamp, #lavalamp.act1 {
left: 35px;
}
#nav li:nth-of-type(2):hover ~ #lavalamp, #lavalamp.act2 {
left: 180px;
}
#nav li:nth-of-type(3):hover ~ #lavalamp, #lavalamp.act3{
left: 345px;
}
#nav li:nth-of-type(4):hover ~ #lavalamp, #lavalamp.act4 {
left: 486px;
}
#nav li:nth-of-type(5):hover ~ #lavalamp, #lavalamp.act5 {
left: 620px;
}
<div id="menucon">
<ul class="innercon" id="nav">
<li>HOME PAGE</li>
<li>PRODUCTS
<ul class="subs sec">
<li class="sec">LEVEL 1
<ul class="subs third">
<li>LEVEL 2</li>
<li>LEVEL 2</li>
</ul>
</li>
<li>LEVEL 1</li>
<li>LEVEL 1</li>
<li>LEVEL 1</li>
<li>LEVEL 1</li>
<li>LEVEL 1</li>
</ul>
</li>
<li>CONTACT US</li>
<div id="lavalamp"></div>
</ul>
</div>
Here is a DEMO to try if it fits your problem.
You gonna have to add this just this css:
.third{
display: none;
}
li > ul.sec > li:hover > ul.third {
display: inline-block;
position: absolute;
left: 100%!important;
top: 0!important;
z-index: 9;
width: 150px;
}
Explanation:
when you hover your second level item (li) you will show your submenu 100% left, i.e. next to the hovered li and top: 0 will place it inline with the hovered li.
You can adjust the width and z-index for your needs.
is this what you wanted?
Your question is still kinda unclear what you want.
ul.sec {
overflow: visible !important;
}
.subs .third {
left: 228px !important;
top: 41px !important;
}
https://jsfiddle.net/gsw4jxy8/4/

how to Add sub menu to dropdown menu

I want to add sub-menu to this drop down function,but i have little knowledge of css , i am not getting how to do this. i want the sub-menu open to right side when cursor is placed on it Here is the css and html relating to it
CSS
ul.dark_menu {
list-style: none;
padding: 5px 1px;
font-family:'Segoe UI Light', 'Open Sans', Verdana, Arial, Helvetica, sans-serif;
font-weight: 200;
font-size: 16px;
letter-spacing: 0.01em;
font-smooth: always;
color: #000000;
line-height: 15px;
margin: auto;
width: 1018px;
position: relative;
background: #2B5797;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu:after {
content:"";
clear: both;
display: block;
overflow: hidden;
visibility: hidden;
width: 0;
height: 0;
}
ul.dark_menu li {
float: left;
position: relative;
margin: 1px;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li a, ul.dark_menu li a:link {
color: #fafafa;
text-decoration: none;
display: block;
padding: 8px 26px;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
-ms-transition: all 0.2s ease;
transition: all 0.2s ease;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li a:hover {
color: #fafafa;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li a.selected {
border-right: 1px solid #ddd;
text-transform: uppercase;
margin-left: 10px;
}
ul.dark_menu li a.selected, ul.dark_menu li a:active {
color: #fafafa;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
ul.dark_menu li ul {
display: none;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li ul:before {
content:" ";
position: absolute;
display: block;
z-index: 1500;
left: 0;
top: -10px;
height: 10px;
width: 100%;
}
ul.dark_menu li ul {
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
top:55px;
}
ul.dark_menu li:hover ul {
position: absolute;
display: block;
z-index: 1000;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
left: 0;
border-radius: 0px 0px 5px 5px;
top: 37px;
padding: 5px 0;
list-style: none;
background: #fff;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li ul li {
float: none;
margin:0px;
}
ul.dark_menu li ul li:first-child {
margin:0px;
border-top: 0 none;
}
ul.dark_menu li ul li:last-child {
border-bottom: 0 none;
}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu[data-role="dropdown"] > a::before {
position: absolute;
content:"^";
display: block;
font-size: 15px;
left: 100%;
margin-left: -20px;
top: 10px;
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
}
ul.dark_menu li ul li a, ul.dark_menu li ul li a:link {
color: #222;
display: block;
background: transparent none;
padding: 10px 25px 10px 25px;
white-space: nowrap;
}
ul.dark_menu li ul li a:hover {
background:#2D89EF;
-moz-transition: all 0.1s ease-in-out;
color:#fff;
-webkit-transition: all 0.1s ease-in-out;
}
/* Blog johanes djogzs.blogspot.com */
.menujohanes {
position:relative;
}
#search input[type="text"]:hover {
width:848px;
}
#search input[type="text"] {
background: #fff url("http://3.bp.blogspot.com/-uYZni0pIn-E/T-xY2vVu_-I/AAAAAAAACUY/ZMfR3_BvRFE/s1600/SEARCH_32x32-32.png")no-repeat center left;
font-size: 13px;
color: #222;
width: 0px;
padding: 10px 0px 11px 35px;
z-index: 9;
border: 1px solid #fff;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
margin-bottom: -1px;
position: absolute;
top: 0px;
right:27px;
}
#main4, #main5, #main6 {
width: 303px;
list-style-type: none;
float: left;
margin: 10px;
}
.main3 {
width:305px;
list-style-type: none;
padding-top: 10px;
float: left;
}
::-webkit-scrollbar {
height:12px;
background: #474747;
}
::-webkit-scrollbar-thumb {
background-color: #000;
}
HTML
<div class='menujohanes'>
<ul class='dark_menu'>
<li>
<a class='selected' expr:href='data:blog.homepageUrl' title='Home'>
Home
</a>
</li>
<li data-role='dropdown'>
<a href='#'>
Categories
</a>
<ul>
<li>
<a href='#'>
Lorem ipsum
</a>
</li>
<li>
<a href='#'>
Lorem ipsum
</a>
</li>
<li>
<a href='#'>
Lorem ipsum
</a>
</li>
<li>
<a href='#'>
Lorem ipsum
</a>
</li>
<li>
<a href='#'>
Download
</a>
</li>
<li>
<a href='#'>
Lorem ipsum
</a>
</li>
</ul>
</li>
</ul>
<form action='/search' id='search' method='get'>
<input name='q' placeholder='Search Somethings..' size='40' type='text'/>
</form>
</div>
Please help as I did search over Google for it but didn't understood how to include sub-menu into this.
Thanks
Try this
<li class='sub'>
<a href='#'>Lorem ipsum </a>
<ul>
<li>
<a href='#'>
sub-item 1
</a>
</li>
</ul>
</li>
and in css add this
li.sub ul {
display:none;
position: absolute; left: 100%; top:0;}
li.sub:hover ul{
display: block;}
For creating new sub menus just add class='sub' to the < li> and add new < ul> below it as a child .
Example: http://jsfiddle.net/6kDG8/2/
Try this:
ul.dark_menu li ul li ul li { display: none; }
ul.dark_menu li ul li:hover ul li { display: block;}
ul.dark_menu li ul li:hover ul { left: 100%; top: 0; }
http://jsfiddle.net/tkbub/1/
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
padding:0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: left;
margin-right: 1px;
}
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
padding:0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: left;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding: 10px 0;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
#media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Only Navigation Menu</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul id="menu">
<li>Home</li>
<li>
About ↓
<ul class="hidden">
<li>Who We Are</li>
<li>What We Do</li>
</ul>
</li>
<li>
Portfolio ↓
<ul class="hidden">
<li>Photography</li>
<li>Web & User Interface Design</li>
<li>Illustration</li>
</ul>
</li>
<li>News</li>
<li>Contact</li>
</ul>
</body>
</html