I modified this menu and added css opacity hover transition.
It only works on the first ul, but the nested sub ul's will not show.
https://jsfiddle.net/sh73vvgf/
Replacing the fade effect with display: none; will show the sub menus.
https://jsfiddle.net/v8op2tqv/
How can I get fade to work on the sub menus? I need it to be pure html/css.
HTML
This nested menu shows a list of Planets and their Moons.
<div class="nav-main">
<ul>
<li>
Planets
<ul>
<li>
Jupiter
<!-- Moons -->
<ul>
<li>
Europa
</li>
<li>
Ganymede
</li>
<li>
Callisto
</li>
</ul>
</li>
<li>
Saturn
<!-- Moons -->
<ul>
<li>
Mimas
</li>
<li>
Dione
</li>
<li>
Titan
</li>
</ul>
</li>
<li>
Uranus
<!-- Moons -->
<ul>
<li>
Umbriel
</li>
<li>
Ariel
</li>
<li>
Oberon
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
CSS
.nav-main ul {
cursor: default;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
position: relative;
width: 300px;
padding: 0;
margin: 0;
background: #000;
font-size: 1em;
color: #fff;
list-style: none;
}
.nav-main ul li {
display: block;
position: relative;
float: left;
min-width: 25%;
padding: 0.3em;
min-width: 100px;
}
.nav-main ul li a {
display: block;
padding: 1.2em;
text-decoration: none;
text-align: center;
white-space: nowrap;
color: #fff;
}
/* Hover Fade */
.nav-main li ul {
webkit-transition: opacity 0.3s ease-out, -webkit-transform 0.3s ease-out;
-moz-transition: opacity 0.3s ease-out, -moz-transform 0.3s ease-out;
transition: opacity 0.3s ease-out, transform 0.3s ease-out;
opacity: 0;
height: 0;
width: 0;
overflow: hidden;
}
.nav-main li:hover > ul {
display: block;
position: absolute;
opacity: 1;
height: auto;
width: auto;
}
.nav-main li:hover li {
float: none;
}
.nav-main ul ul ul {
left: 100%;
top: 0;
}
.nav-main ul:before,
.nav-main ul:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.nav-main ul:after {
clear: both;
}
I changed some "overflow" style of your code.
.nav-main ul {
cursor: default;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
position: relative;
width: 300px;
padding: 0;
margin: 0;
background: #000;
font-size: 1em;
color: #fff;
list-style: none;
overflow:hidden;
}
.nav-main ul:hover {
overflow:visible;
}
.nav-main ul li {
display: block;
position: relative;
float: left;
min-width: 25%;
padding: 0.3em;
min-width: 100px;
}
.nav-main ul li a {
display: block;
padding: 1.2em;
text-decoration: none;
text-align: center;
white-space: nowrap;
color: #fff;
}
/* Hover Fade */
.nav-main li ul {
webkit-transition: opacity 0.3s ease-out, -webkit-transform 0.3s ease-out;
-moz-transition: opacity 0.3s ease-out, -moz-transform 0.3s ease-out;
transition: opacity 0.3s ease-out, transform 0.3s ease-out;
opacity: 0;
height: 0;
width: 0;
//overflow: hidden;
}
.nav-main li:hover > ul {
display: block;
position: absolute;
opacity: 1;
height: auto;
width: auto;
}
.nav-main li:hover li {
float: none;
}
.nav-main ul ul ul {
left: 100%;
top: 0;
}
.nav-main ul:before,
.nav-main ul:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.nav-main ul:after {
clear: both;
}
<div class="nav-main">
<ul>
<li>
Planets
<ul>
<li>
Jupiter
<!-- Moons -->
<ul>
<li>
Europa
</li>
<li>
Ganymede
</li>
<li>
Callisto
</li>
</ul>
</li>
<li>
Saturn
<!-- Moons -->
<ul>
<li>
Mimas
</li>
<li>
Dione
</li>
<li>
Titan
</li>
</ul>
</li>
<li>
Uranus
<!-- Moons -->
<ul>
<li>
Umbriel
</li>
<li>
Ariel
</li>
<li>
Oberon
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Related
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>
hello is it possible that when I hover to the parent item the parent item will also slide up making the drop down menu with parent item above it? here is my code but I cant seem to make it work. here is a visual menu that i want http://imgur.com/om9mvdG (the second image)
.nav ul {
*zoom: 1;
list-style: none;
margin: 0;
padding: 0;
background: #333;
}
.nav ul:before,
.nav ul:after {
content: "";
display: table;
}
.nav ul:after {
clear: both;
}
.nav ul > li {
float: left;
position: relative;
}
.nav a {
display: block;
padding: 10px 20px;
line-height: 1.2em;
color: #fff;
border-left: 1px solid #595959;
}
.nav a:hover {
text-decoration: none;
background: #595959;
}
.nav li ul {
background: #273754;
position: absolute;
left: 0;
bottom: 36px;
z-index: 1;
}
.nav li ul li {
width: 100%;
overflow: hidden;
height: 0;
-webkit-transition: height 200ms ease-in;
-moz-transition: height 200ms ease-in;
-o-transition: height 200ms ease-in;
transition: height 200ms ease-in;
}
.nav li ul a {
border: none;
}
.nav li ul a:hover {
background: rgba(0, 0, 0, 0.2);
}
.nav ul > li:hover ul li {
height: 36px;
}
<ul>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
</ul>
</nav>
Add this css to your already existing code. Is this what you wanted?
http://codepen.io/anon/pen/jbBgdg
li>ul {
display: none;
}
a:hover~ul {
display: block;
}
I am learning css and I have created a vertical menu, hovering the mouse over the first menu item shows the sub-menu across. But my problem is, as soon as I move the mouse to the sub-menu, it disappears. How can I make it so it stays there until I clicked one of the sub-menu items? Please help.
Already searched through a lot of examples but none similar to this. I'm new to css and I'm not sure if my approach is the correct for this menu setup requirement. Please enlighten.
#charset "utf-8";
.navLeft {
width: 25%;
margin-top: 0%;
top: auto;
display: inline;
list-style-type: none;
margin-left: 5%;
position: relative;
z-index: 0;
/* [disabled]clear: none; */
}
.navLeft ul li {
list-style-type: none;
width: 6em;
height: 2em;
/* [disabled]list-style-position: inside; */
color: #F14E23;
text-align: center;
background-color: #FFFFFF;
border: 0.5em solid #000000;
margin-bottom: -0.5em;
font-family: alfa-slab-one;
font-style: normal;
font-weight: 400;
padding-top: 2em;
top: auto;
vertical-align: middle;
padding-bottom: 2em;
-webkit-transition: all 0.1s linear 0s;
-o-transition: all 0.1s linear 0s;
transition: all 0.1s linear 0s;
position: relative;
margin-left: -0.5em;
}
.navLeft ul li:hover {
background-color: #F14E23;
color: #FFFFFF;
list-style-type: none;
position: relative;
}
.navLeft ul .about {
float: left;
-webkit-transition: all .1s linear 0s;
-o-transition: all .1s linear 0s;
transition: all .1s linear 0s;
}
.navLeft ul ul li
{
float: left;
}
.navLeft ul .projects {
clear: left;
}
.navLeft ul ul {
display: none;
}
.navLeft ul .about:hover ~ ul{
display: block;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>STORY</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<section class="mainMid">
<nav class="navLeft">
<ul>
<li class="about">ABOUT</li>
<ul>
<li class="navBeginning">BEGINNING</li>
<li class="navMnv">Mission<br>
<br>
Vision</li>
<li class="navPeople">People</li>
</ul>
<li class="projects">PROJECTS</li>
<li class="getinvolved">GET<br>
INVOLVED</li>
<li class="records">RECORDS</li>
<li class="donate">DONATE</li>
</ul>
</nav>
</section>
</body>
</html>
Refer this fiddle : http://jsfiddle.net/zt8ffu11/
html:
<section class="mainMid">
<nav class="navLeft">
<ul>
<li class="about">ABOUT
<ul>
<li class="navBeginning">BEGINNING</li>
<li class="navMnv">Mission<br>
<br>
Vision</li>
<li class="navPeople">People</li>
</ul>
</li>
<li class="projects">PROJECTS</li>
<li class="getinvolved">GET<br>
INVOLVED</li>
<li class="records">RECORDS</li>
<li class="donate">DONATE</li>
</ul>
</nav>
</section>
css:
.navLeft {
width: 25%;
margin-top: 0%;
top: auto;
display: inline;
list-style-type: none;
margin-left: 5%;
position: relative;
z-index: 0;
/* [disabled]clear: none; */
}
.navLeft ul li {
list-style-type: none;
width: 6em;
height: 2em;
/* [disabled]list-style-position: inside; */
color: #F14E23;
text-align: center;
background-color: #FFFFFF;
border: 0.5em solid #000000;
margin-bottom: -0.5em;
font-family: alfa-slab-one;
font-style: normal;
font-weight: 400;
padding-top: 2em;
top: auto;
vertical-align: middle;
padding-bottom: 2em;
-webkit-transition: all 0.1s linear 0s;
-o-transition: all 0.1s linear 0s;
transition: all 0.1s linear 0s;
position: relative;
margin-left: -0.5em;
}
.navLeft ul li:hover {
background-color: #F14E23;
color: #FFFFFF;
list-style-type: none;
position: relative;
}
.navLeft ul .about {
float: left;
-webkit-transition: all .1s linear 0s;
-o-transition: all .1s linear 0s;
transition: all .1s linear 0s;
}
.navLeft ul ul li
{
float: left;
}
.navLeft ul .projects {
clear: left;
}
.navLeft ul ul {
display: none;
}
.navLeft ul .about:hover ul{
display: block;
}
and for list structure check is question Proper way to make HTML nested list?
I can't get this to work, but in my dropdown menu I just simply can't find a way to make the dropdown menu (for example on account) have it scale with the text.
I tried many things, but only so far a static width is working but that is not what I want
<div class="menu-wrap">
<div class="menu">
<ul class="menu-inner">
<li class="home">Home</li>
<li class="account">Mijn Account
<ul>
<li>Mijn website</li>
<li>Profiel</li>
<li>Persoonlijke gegevens</li>
<li>Voorkeuren</li>
<li>Email instellingen</li>
<li>Log uit</li>
</ul>
</li>
<li class="pages">Mijn pagina's
<ul>
<li>Mijn pagina's</li>
<li>Maak een nieuwe pagina</li>
<li>Verander pagina volgorde</li>
</ul>
</li>
<li class="messages">Mijn berichten
<ul>
<li>Alle privè berichten</li>
<li>Verzonden berichten</li>
<li>Verwijderde berichten</li>
<li>Ongelezen berichten</li>
</ul>
</li>
<li class="forum">Forum
<ul>
<li>Nieuwste berichten</li>
<li>Overzicht</li>
<li>Mijn berichten</li>
<li>Top posters</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="search">Zoeken
<ul>
<li>Zoeken</li>
<li>Vandaag jarig</li>
<li>Online leden</li>
<li>Alle leden</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="online">Online (x)
</ul>
</div>
</div>
and the css code:
.menu-wrap{
position: relative;
background-color: rgba(0,0,0,0.8);
height: 30px;
width: 100%;
text-align: center;
}
.menu {
position: relative;
width: 860px;
margin: 0px auto;
height: 30px;
line-height: 30px;
}
.menu ul {
text-align: left;
display: inline;
margin: 0;
padding: 0;
list-style: none;
}
.menu ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 5px 22px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
background-color: rgba(0,0,0,0.4);
}
.menu ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
.menu ul li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: auto;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
background-color: rgba(0,0,0,0.4)
}
.menu ul li ul li {
color: #fff;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0,0.4);}
.menu ul li:hover ul {
display:inline-block;
opacity: 1;
visibility: visible;
}
All I want is have the sub menus auto scale in width with the text!
You are going to have to add a white-space property to the .menu ul li ul li rule like so:
.menu ul li ul li {
white-space: nowrap;
}
I have a navigation menu that I'm trying to get to work, but the submenus keep switching to another submenu whenever I hover over it. How can I get it so that the right menu stays up when I hover over it?
jsfiddle: http://jsfiddle.net/SHQwm/
.hoverBar {
position: relative;
border: 1px solid #d6d6d6;
background: #fff;
padding: 15px 20px;
height: 100px;
}
ul {
margin: 0;
padding: 0;
width: 1152px;
}
.mainmenu > li {
list-style: none;
float:left;
text-align: center;
}
ul.mainmenu > li a {
font-family: 'Open Sans', sans-serif;
padding: 0 10px;
font-size: 11px;
text-decoration: none;
text-transform: uppercase;
}
ul li ul {
opacity: 0;
transition: opacity .15s ease-in-out;
-moz-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
-o-transition: opacity .15s ease-in-out;
list-style-type: none;
text-align: left;
float: left;
width: 100%;
position: absolute;
z-index: 60;
left: 0;
padding-top: 30px;
}
ul li:hover ul {
opacity: 1;
}
ul li ul li {
float: left;
text-align: left;
border-top: #4c4c4c 1px solid;
border-bottom: #303030 1px solid;
border-radius: 2px;
margin-bottom: 0;
padding: 10px 0;
white-space: nowrap;
width: auto;
}
ul li ul li:hover {
background-color: #008000;
}
.floatr {
position: absolute;
top: 10px;
z-index: 50;
width: 100px;
height: 30px;
background : #ebebeb;
opacity: 0.25;
-ms-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
border-top: solid 1px #00aced;
border-bottom: solid 1px #00aced;
}
.mainmenu > li:hover > a {
opacity: 1;
}
ul li ul li a {
display: block;
padding: 0px;
line-height: 14px;
font-size: 12px;
color: #000;
font-family: 'Open Sans', sans-serif;
text-transform: none !important;
text-align: left;
}
ul li:hover ul li {
display:block;
}
.mainmenu {
height: 100px;
}
#jobBank {
left: 450;
width: 210px;
}
And the HTML:
<nav class="head_nav">
<div class="hoverBar" >
<ul class="mainmenu">
<li class="active">About
<ul style="background-color: red;">
<li>Mission</li>
<li>Board Members</li>
<li>Staff</li>
<li>Members</li>
<li>Task Forces</li>
</ul>
</li>
<li>Events
<ul style="background-color: green;">
<li>Description</li>
<li>Registration with Outlook ICS</li>
<li>Online Payment</li>
<li>Email auto-reminders</li>
<li>Multiple registrants allowed</li>
</ul>
</li>
<li>Galleries
<ul style="background-color: blue;">
<li>EXAMPLE: Executive Board</li>
<li>EXAMPLE: Single Page or Blog Page</li>
<li>EXAMPLE: Photo Gallery</li>
</ul>
</li>
<li>Educational Resources</li>
<li>Economic Development
<ul style="background-color: yellow;">
<li>Major Corporations/Global Businesses</li>
<li>Maps</li>
<li>Available Properties</li>
<li>Communities Represented</li>
<li>Demographics</li>
<li>Workforce</li>
<li>Taxes</li>
<li>Transportation</li>
<li>Utilities</li>
<li>Incentives & Financing</li>
<li>Report and Publications</li>
</ul>
</li>
</li>
<li>Media Room
<ul>
<li class="first">Press Releases</li>
<li>Media Kit Information</li>
<li>Blog</li>
<li>Link to Logo & Standards</li>
<li>Link to Photo Gallery</li>
<li>Twitter, Facebook, LinkedIn, Flickr</li>
<li>Speakers Bureau List/info</li>
<li>Fact Sheet</li>
<li class="last">Media Relations Contact</li>
</ul>
</li>
<li>Job Bank
<ul id="jobBank">
<li class="first">Member Add/Edit/Delete</li>
<li class="last">Time Expire</li>
</ul>
</li>
</ul>
<div class="floatr"></div>
</div>
</nav>
Remove opacity: 0 from ul li ul. Replace it with display: none;. Remove opacity: 1 from ul li:hover ul. Replace it with display: block;. Currently, all of the subnavigations are there, you just can't see them. Setting them to display: none; by default will only display the correct one when the parent navigation element is hovered and will remove the issue you're having. http://jsfiddle.net/SHQwm/5/