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>
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>
Right now whenever you hover one of the <a> elements a div transitions from left to right under the hovered element, however, when I stop hovering it disappears instantly instead of hovering back. How can I make it so it hovers back to it's original position?
What I have so far is this:
*, *:after, *:before {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
list-style-type: none;
color: rgba(0, 0, 0, 0.8);
}
.links {
display: flex;
font-size: 1.1em;
font-weight: 500;
text-align: center;
}
.links a {
display: flex;
justify-content: center;
align-items: center;
margin: 0px 30px;
padding: 10px 0 10px 0;
position: relative;
}
.links a:after{
content: '';
position: absolute;
width: 0;
height: 4px;
display: block;
margin-top: 25px;
right: 0;
background: #fff;
transition: width .2s ease;
-webkit-transition: width .3s ease;
}
.links a:hover:after{
width: 100%;
left: 0;
background: rgba(0, 0, 0, 0.8);
}
<div class='links'>
<a href=''>
<p>AAAAAAAAAAAAAAAA</p>
</a>
<a href=''>
<p>AAAAAAAAAAAAAAAA</p>
</a>
<a href="">
<p>AAAAAAAAAAAAAAAA</p>
</a>
</div>
Here is a solution, try this.
.footer_menu {
padding: 30px 0 0;
}
.footer_menu ul {
padding: 0;
text-align: left;
margin-bottom: 0;
list-style: none;
}
.footer_menu ul.bottom-menu {
margin-bottom: 20px;
}
.footer_menu ul li {
margin-bottom: 10px;
list-style: none;
}
.footer_menu ul li a {
text-decoration: none;
color: #666666;
padding-bottom: 3px;
position: relative;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.footer_menu ul li a::before {
content: '';
position: absolute;
bottom: -3px;
left: 0;
right: 100%;
height: 2px;
background: #e5e5e5;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
visibility: hidden;
}
.footer_menu ul li a:hover {
color: #000000;
}
.footer_menu ul li a:hover::before {
left: 0;
right: 0;
background: red;
visibility: visible;
}
<div class="footer_menu">
<ul>
<li>test test</li>
<li>test test</li>
</ul>
<div>
You cas use ease-in by default and on :hover ease-out
This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed 3 years ago.
.topmenu-header ul {
position: absolute;
list-style-type: none;
width: 100%;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul li {
cursor: pointer;
float: left;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: relative;
background: red;
padding: 16px;
color: white;
transition: all 5s ease 0s;
}
.topmenu-header .dropdown {
top: 100%;
left: inherit;
display: none;
}
.topmenu-header li:hover .dropdown {
background: pink;
transition-delay: 0s;
display: block;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li>SPECIALS
<div class="dropdown">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
I am trying to add transition on my dropdown hover. But i can't recognize the right place, as where i have to write the code. I want if i hover the menu. the drop down will come up smoothly. It's a mega drop down and come up at quickly on hover. I just wanna make it a little bit slow. So it look awesome.
you mainly need to add transition to your submenu class. I have add the code let me know if you have any confusion
.topmenu-header ul {
position: absolute;
list-style-type: none;
width: 100%;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul li {
cursor: pointer;
float: left;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: relative;
background: red;
padding: 16px;
color: white;
transition: all 5s ease 0s;
}
.sub-menu-parent {
position: relative;
}
.sub-menu {
background: pink;
text-align: center;
display: block;
visibility: hidden;
/* hides sub-menu */
opacity: 0;
position: absolute;
top: 100%;
left: 0;
width: 100%;
z-index: -1;
transition: all 0.3s ease-in-out 0s
}
.sub-menu-parent:focus .sub-menu,
.sub-menu-parent:focus-within .sub-menu,
.sub-menu-parent:hover .sub-menu {
visibility: visible;
/* shows sub-menu */
opacity: 1;
z-index: 1;
transition-delay: 0s, 0s, 0.3s;
}
.topmenu-header .dropdown {
top: 100%;
left: inherit;
display: none;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li class="sub-menu-parent">SPECIALS
<div class="sub-menu">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
Transition opacity while changing max-height (but not transitioning that). Please note that I also removed float: left; and instead made the ul a flex container.
.topmenu-header ul {
position: relative;
list-style-type: none;
display: flex;
background: rgba(255, 0, 0, 1);
flex-wrap: wrap;
}
.topmenu-header ul li {
cursor: pointer;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: absolute;
background: red;
color: white;
max-height: 0;
overflow: hidden;
transition: opacity .4s ease 0s;
}
.topmenu-header .dropdown {
left: inherit;
opacity: 0;
}
.topmenu-header li:hover .dropdown {
background: pink;
padding: 16px;
max-height: 1000px;
opacity: 1;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li>SPECIALS
<div class="dropdown">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
Not all CSS properties can be animated. Here is the MDN list of properties that can be animated - you will see that display is not on the list, so animating the change from display:hidden to display:block cannot be done.
Look through the above list and decide which property you want to animate, and you will be able to create something that works. In the below example, I just picked the height property and you can see that it animates just fine.
.topmenu-header ul {
position: absolute;
list-style-type: none;
width: 100%;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul li {
cursor: pointer;
float: left;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: relative;
background: red;
padding: 16px;
color: white;
transition: all 1.5s ease 0s;
}
.topmenu-header .dropdown {
top: 100%;
left: inherit;
Xdisplay: none;
height:0px;
overflow:hidden;
}
.topmenu-header li:hover .dropdown {
background: pink;
transition-delay: 0s;
xdisplay: block;
height:50px;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li>SPECIALS
<div class="dropdown">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
I'm having a lot of troubles trying to do this. I finally found how to do an expansion animation for an aside menu im doing, when I hover one of its elements.
The problem is that i want to do an animation to close it as well. I tried making an animation as the open animation (with from -> to) and it doesn't work.
I tried making transitions with max height, using the different containers in the list (ul, div, li, whatever one by one), I tried searching different kinds of already made animations, but none worked, the menu just pop out and disappear without animation.
What I basically want is a smooth animation to move the other elements down (reached), and then up when the menu closes.
Actually it has 2 animations: to expand the max height, and to move it from right to left. but I can't reach to close it with animation.
I don't want to use Javascript, because is for school project but we haven't seen it yet.
https://jsfiddle.net/exrp4doa/
#-webkit-keyframes slider {
from {
border-left: 300px
}
to {
border-left: 0px
}
}
#keyframes slider {
from {
margin-left: 300px
}
to {
margin-left: 0px
}
}
#-webkit-keyframes altura {
from {
max-height: 0px
}
to {
max-height: 500px
}
}
#keyframes altura {
from {
max-height: 0px
}
to {
max-height: 500px
}
}
aside {
width: 25%;
display: inline-block;
vertical-align: top;
margin-top: 20px;
margin-bottom: 20px;
}
aside > div:not(#marcador) {
background-color: rgb( 40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-top: 5px;
margin-right: -15px;
font-family: 'Press Start 2P';
font-size: 0.7em;
line-height: 10px;
padding: 15px;
-moz-transition: opacity 0.4s ease-in-out;
-o-transition: opacity 0.4s ease-in-out;
-webkit-transition: opacity 0.4s ease-in-out;
transition: opacity 0.4s ease-in-out;
}
#marcador div {
display: none;
opacity: 0;
visibility: hidden;
position: static;
}
#marcador li:hover >div {
display: block;
opacity: 1;
visibility: visible;
padding-left: 20px;
-webkit-animation-name: slider;
-webkit-animation-duration: 0.5s;
animation-name: slider;
animation-duration: 0.5s;
}
#marcador li li {}
#marcador li:hover li {
-webkit-animation-name: altura;
-webkit-animation-duration: 5s;
animation-name: altura;
animation-duration: 5s;
}
#marcador li:hover >a {
display: block;
opacity: 1;
visibility: visible;
}
#marcador ul {
margin: 0;
padding: 0;
list-style-type: none;
position: static;
}
#marcador ul li>a {
background-color: rgb( 40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-top: 5px;
margin-right: -15px;
font-family: 'Press Start 2P';
font-size: 0.7em;
line-height: 10px;
padding: 15px;
padding-left: 35px;
}
#marcador ul ul {
padding: 0;
margin: auto;
}
#marcador ul ul a {
margin-left: 20px;
background-color: dimgray;
}
#marcador ul ul ul a {
margin-left: 40px;
background-color: gray;
color: black;
}
#marcador img {
float: left;
vertical-align: middle;
display: inline-block;
opacity: 0;
position: absolute;
visibility: hidden;
margin-left: -20px;
}
#marcador li:hover>a>img {
opacity: 1;
visibility: visible;
}
#marcador a:hover {
color: orange;
}
<aside>
<div id="marcador">
<ul>
<li>
<a><img src="Recursos/Select.png" />Inicio</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Juegos</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />Sega</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />Arcade</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Nintendo</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />NES</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Consolas</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES Mini</a>
</li>
<li>
<a><img src="Recursos/Select.png" />NES Mini</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />SEGA GENESIS</a>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Compras</a>
</li>
<li>
<a><img src="Recursos/Select.png" />DIY</a>
</li>
<li>
<a onclick="alert('Página en construcción')"><img id="info" src="Recursos/info.png" alt="INFO" /></a>
</li>
</ul>
</div>
</aside>
You can use transition instead of animation. My demo:
aside {
width: 25%;
display: inline-block;
vertical-align: top;
margin-top: 20px;
margin-bottom: 20px;
}
aside > div:not(#marcador) {
background-color: rgb(40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-top: 5px;
margin-right: -15px;
font-family: "Press Start 2P";
font-size: 0.7em;
line-height: 10px;
padding: 15px;
-moz-transition: opacity 0.4s ease-in-out;
-o-transition: opacity 0.4s ease-in-out;
-webkit-transition: opacity 0.4s ease-in-out;
transition: opacity 0.4s ease-in-out;
}
#marcador li> div {
opacity: 0;
margin-left: 300px;
-webkit-transition: all 0.5s;
transition: all 0.5s;
}
#marcador li:hover > div {
opacity: 1;
padding-left: 20px;
margin-left: 0;
}
#marcador li> div >ul >li {
max-height: 0;
transition: all 0.5s;
}
#marcador li:hover> div >ul >li {
max-height: 40px;
}
#marcador li:hover{
max-height: 500px !important;
}
#marcador li:hover > a {
display: block;
opacity: 1;
visibility: visible;
}
#marcador ul {
margin: 0;
padding: 0;
list-style-type: none;
position: static;
}
#marcador ul li > a {
background-color: rgb(40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-right: -15px;
font-family: "Press Start 2P";
font-size: 0.7em;
line-height: 10px;
padding: 15px;
padding-left: 35px;
}
#marcador ul ul {
padding: 0;
margin: auto;
}
#marcador ul ul a {
margin-left: 20px;
background-color: dimgray;
}
#marcador ul ul ul a {
margin-left: 40px;
background-color: gray;
color: black;
}
#marcador img {
float: left;
vertical-align: middle;
display: inline-block;
opacity: 0;
position: absolute;
visibility: hidden;
margin-left: -20px;
}
#marcador li:hover > a > img {
opacity: 1;
visibility: visible;
}
#marcador a:hover {
color: orange;
}
<aside>
<div id="marcador">
<ul>
<li>
<a><img src="Recursos/Select.png" />Inicio</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Juegos</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />Sega</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />Arcade</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Nintendo</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />NES</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Consolas</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES Mini</a>
</li>
<li>
<a><img src="Recursos/Select.png" />NES Mini</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />SEGA GENESIS</a>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Compras</a>
</li>
<li>
<a><img src="Recursos/Select.png" />DIY</a>
</li>
<li>
<a onclick="alert('Página en construcción')"><img id="info" src="Recursos/info.png" alt="INFO" /></a>
</li>
</ul>
</div>
</aside>
#menu {
width: 100%;
margin: 10px auto;
}
#menu ul,
#menu li {
margin: 0 auto;
padding: 0 0;
list-style: none
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
}
#menu li a {
border-right: 1px solid #e5e5e5;
}
#menu li a:hover {
color: #444;
background-color: #e5e5e5;
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 30px;
opacity: 0;
}
#menu label {
font-size: 20px;
display: none;
width: 35px;
height: 20px;
line-height: 20px;
text-align: center;
color: #77778b
}
#menu label span {
position: absolute;
left: 35px;
}
#menu ul.menus {
height: auto;
overflow: hidden;
width: 180px;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
position: absolute;
z-index: 99;
display: none;
left: -1px;
}
#menu ul.menus li {
display: block;
width: 100%;
}
#menu ul.menus a {
color: #77778b;
}
#menu li:hover ul.menus {
display: block
}
<nav id='menu'>
<input type='checkbox' />
<label><i class='icon-reorder' /><span>Menu</span>
</label>
<ul>
<li><a href='/'>Home</a>
</li>
<li><a class='dropdown' href='#'>Menu1</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
</ul>
</li>
<li><a class='dropdown' href='#'>Menu2</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
<li><a href='#'>Submenu3</a>
</li>
</ul>
</li>
</ul>
</nav>
How can I make the Dropdowns Fade in with only CSS? A bit noobish question but still trying to understand CSS Any one have any idea how to make it possible plz suggest it.
Thanks !
One possible solution is to use opacity: 0 instead of display: none and using transition on hover:
#menu {
width: 100%;
margin: 10px auto;
}
#menu ul,
#menu li {
margin: 0 auto;
padding: 0 0;
list-style: none
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
}
#menu li a {
border-right: 1px solid #e5e5e5;
}
#menu li a:hover {
color: #444;
background-color: #e5e5e5;
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 30px;
opacity: 0;
}
#menu label {
font-size: 20px;
display: block;
width: 35px;
height: 20px;
line-height: 20px;
text-align: center;
color: #77778b;
visibility: hidden;
}
#menu label span {
position: absolute;
left: 35px;
}
#menu ul.menus {
height: auto;
overflow: hidden;
width: 180px;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
position: absolute;
z-index: 99;
display: block;
left: -1px;
opacity: 0;
}
#menu ul.menus li {
display: block;
width: 100%;
}
#menu ul.menus a {
color: #77778b;
}
#menu li:hover ul.menus {
opacity: 1;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
<nav id='menu'>
<input type='checkbox' />
<label><i class='icon-reorder' /><span>Menu</span>
</label>
<ul>
<li><a href='/'>Home</a>
</li>
<li><a class='dropdown' href='#'>Menu1</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
</ul>
</li>
<li><a class='dropdown' href='#'>Menu2</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
<li><a href='#'>Submenu3</a>
</li>
</ul>
</li>
</ul>
</nav>
Also you can use transition same way to animate on mouse out:
#menu {
width: 100%;
margin: 10px auto;
}
#menu ul,
#menu li {
margin: 0 auto;
padding: 0 0;
list-style: none
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
}
#menu li a {
border-right: 1px solid #e5e5e5;
}
#menu li a:hover {
color: #444;
background-color: #e5e5e5;
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 30px;
opacity: 0;
}
#menu label {
font-size: 20px;
display: block;
width: 35px;
height: 20px;
line-height: 20px;
text-align: center;
color: #77778b;
visibility: hidden;
}
#menu label span {
position: absolute;
left: 35px;
}
#menu ul.menus {
height: auto;
overflow: hidden;
width: 180px;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
position: absolute;
z-index: 99;
display: block;
left: -1px;
opacity: 0;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#menu ul.menus li {
display: block;
width: 100%;
}
#menu ul.menus a {
color: #77778b;
}
#menu li:hover ul.menus {
opacity: 1;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
<nav id='menu'>
<input type='checkbox' />
<label><i class='icon-reorder' /><span>Menu</span>
</label>
<ul>
<li><a href='/'>Home</a>
</li>
<li><a class='dropdown' href='#'>Menu1</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
</ul>
</li>
<li><a class='dropdown' href='#'>Menu2</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
<li><a href='#'>Submenu3</a>
</li>
</ul>
</li>
</ul>
</nav>