Why is this section is acting very wierd when hovered? - html

This is a side-navbar file which I made by watching a youtube video and I tweaked some things in it and its working fine but there's a little problem.
Whenever I hover on the profile info box which is on bottom it starts to dance. Why?
let arrow = document.querySelectorAll(".arrow");
for (var i = 0; i < arrow.length; i++) {
arrow[i].addEventListener("click", (e) => {
let arrowParent = e.target.parentElement.parentElement; //selecting main parent of arrow
arrowParent.classList.toggle("showMenu");
});
}
let sidebar = document.querySelector(".sidebar");
let sidebarBtn = document.querySelector(".bx-menu");
console.log(sidebarBtn);
sidebarBtn.addEventListener("click", () => {
sidebar.classList.toggle("close");
});
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 260px;
z-index: 100;
transition: all 0.5s ease;
backdrop-filter: blur(25px);
box-shadow: 10px 0 15px rgba(0, 0, 0, 0.1);
}
.sidebar.close {
width: 78px;
}
.sidebar .logo-details {
height: 60px;
width: 100%;
display: flex;
align-items: center;
}
.sidebar .logo-details i {
font-size: 30px;
color: #444444;
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
}
.sidebar .logo-details .logo_name {
font-size: 22px;
color: #444444;
font-weight: 600;
transition: 0.3s ease;
transition-delay: 0.1s;
}
.sidebar.close .logo-details .logo_name {
transition-delay: 0s;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links {
height: 100%;
padding: 30px 0 150px 0;
overflow: auto;
}
.sidebar.close .nav-links {
overflow: visible;
}
.sidebar .nav-links::-webkit-scrollbar {
display: none;
}
.sidebar .nav-links li {
position: relative;
list-style: none;
transition: all 0.4s ease;
}
.sidebar .nav-links li:hover {
backdrop-filter: blur(40px);
box-shadow: 10px 0 15px rgba(0, 0, 0, 0.1);
}
.sidebar .nav-links li .iocn-link {
display: flex;
align-items: center;
justify-content: space-between;
}
.sidebar.close .nav-links li .iocn-link {
display: block
}
.sidebar .nav-links li i {
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
color: #444444;
font-size: 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.sidebar .nav-links li.showMenu i.arrow {
transform: rotate(-180deg);
}
.sidebar.close .nav-links i.arrow {
display: none;
}
.sidebar .nav-links li a {
display: flex;
align-items: center;
text-decoration: none;
}
.sidebar .nav-links li a .link_name {
font-size: 18px;
font-weight: 400;
color: #444444;
transition: all 0.4s ease;
}
.sidebar.close .nav-links li a .link_name {
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li .sub-menu {
padding: 6px 6px 14px 80px;
margin-top: -10px;
display: none;
backdrop-filter: blur(25px);
box-shadow: 10px 0 15px rgba(0, 0, 0, 0.1);
}
.sidebar .nav-links li.showMenu .sub-menu {
display: block;
}
.sidebar .nav-links li .sub-menu a {
color: #444444;
font-size: 15px;
padding: 5px 0;
white-space: nowrap;
opacity: 0.6;
transition: all 0.3s ease;
}
.sidebar .nav-links li .sub-menu a:hover {
opacity: 1;
}
.sidebar.close .nav-links li .sub-menu {
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 10px 20px;
border-radius: 0 6px 6px 0;
opacity: 0;
display: block;
pointer-events: none;
transition: 0s;
}
.sidebar.close .nav-links li:hover .sub-menu {
top: 0;
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
}
.sidebar .nav-links li .sub-menu .link_name {
display: none;
}
.sidebar.close .nav-links li .sub-menu .link_name {
font-size: 18px;
opacity: 1;
display: block;
}
.sidebar .nav-links li .sub-menu.blank {
opacity: 1;
pointer-events: auto;
padding: 3px 20px 6px 16px;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li:hover .sub-menu.blank {
top: 50%;
transform: translateY(-50%);
}
.sidebar .profile-details {
position: fixed;
bottom: 0;
width: 260px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 0;
transition: all 0.5s ease;
backdrop-filter: blur(60px);
box-shadow: 10px 0 15px rgba(0, 0, 0, 0.1);
}
.sidebar.close .profile-details {
background: none;
}
.sidebar.close .profile-details {
width: 78px;
}
.sidebar .profile-details .profile-content {
display: flex;
align-items: center;
}
.sidebar .profile-details img {
height: 40px;
width: 40px;
object-fit: cover;
border-radius: 16px;
margin: 0 14px 0 12px;
transition: all 0.5s ease;
backdrop-filter: blur(70px);
box-shadow: 10px 0 15px rgba(0, 0, 0, 0.1);
}
.sidebar.close .profile-details img {
padding: 10px;
}
.sidebar .profile-details .profile_name,
.sidebar .profile-details .job {
color: #444444;
font-size: 18px;
font-weight: 500;
white-space: nowrap;
}
.sidebar.close .profile-details i,
.sidebar.close .profile-details .profile_name,
.sidebar.close .profile-details .job {
display: none;
}
.sidebar .profile-details .job {
font-size: 12px;
}
.home-section {
position: relative;
height: 100vh;
left: 260px;
width: calc(100% - 260px);
transition: all 0.5s ease;
background: brown;
opacity: 0.2;
}
.sidebar.close~.home-section {
left: 78px;
width: calc(100% - 78px);
}
.home-section .home-content {
height: 60px;
display: flex;
align-items: center;
}
.home-section .home-content .bx-menu,
.home-section .home-content .text {
color: #11101d;
font-size: 35px;
}
.home-section .home-content .bx-menu {
margin: 0 15px;
cursor: pointer;
}
.home-section .home-content .text {
font-size: 26px;
font-weight: 600;
}
#media (max-width: 420px) {
.sidebar.close .nav-links li .sub-menu {
display: none;
}
}
<div class="sidebar close">
<div class="logo-details">
<i class='bx bx-library'></i>
<span class="logo_name">E-Library</span>
</div>
<ul class="nav-links">
<li>
<a href="#">
<i class='bx bx-grid-alt'></i>
<span class="link_name">Dashboard</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Category</a></li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-collection'></i>
<span class="link_name">Category</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Category</a></li>
<li>HTML & CSS</li>
<li>JavaScript</li>
<li>PHP & MySQL</li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-book-alt'></i>
<span class="link_name">Posts</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Posts</a></li>
<li>Web Design</li>
<li>Login Form</li>
<li>Card Design</li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-pie-chart-alt-2'></i>
<span class="link_name">Analytics</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Analytics</a></li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-line-chart'></i>
<span class="link_name">Chart</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Chart</a></li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-plug'></i>
<span class="link_name">Plugins</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Plugins</a></li>
<li>UI Face</li>
<li>Pigments</li>
<li>Box Icons</li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-compass'></i>
<span class="link_name">Explore</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Explore</a></li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-history'></i>
<span class="link_name">History</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">History</a></li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-cog'></i>
<span class="link_name">Settings</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Settings</a></li>
</ul>
</li>
<li>
<div class="profile-details">
<div class="profile-content">
<img src="image/profile.jpg" alt="profileImg">
</div>
<div class="name-job">
<div class="profile_name">Sam</div>
<div class="job">Student</div>
</div>
<i class='bx bx-log-out'></i>
</div>
</li>
</ul>
</div>
<section class="home-section">
<div class="home-content">
<i class='bx bx-menu'></i>
</div>
</section>

It seems like fixed position is creating problems with the backdrop-filter. Try to replace:
.sidebar .nav-links li:hover{
backdrop-filter: blur(40px);
box-shadow: 10px 0 15px rgba(0,0,0,0.1);
}
with:
.sidebar .nav-links li:hover:not(.sidebar .nav-links li:last-child){
backdrop-filter: blur(40px);
box-shadow: 10px 0 15px rgba(0,0,0,0.1);}
}

Related

How can I add another submenu under the submenu?

I tried to use the same pattern in creating submenu, and its displaying but the problem is its already showing when I only trying to view the submenu
<ul class="nav-links">
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-collection'></i>
<span class="link_name">Patient Information Module</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Patient Information</a></li>
<li>Patient</li>
<li>Dental</li>
<li>Immunization</li>
<li>Pediatric</li>
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-collection'></i>
<span class="link_name">Pediatric</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Immunization</a></li>
<li>Deworming</li>
<li>Vitamins/Suppliments</li>
</ul>
</li>
<li>TB Dots</li>
<li>OB</li>
</ul>
</li>
Please refer this :
Use JavaScript and CSS for hide and show submenu on click or hover
document.addEventListener('click', function(e) {
e = e || window.event;
console.log(e);
var target = e.target || e.srcElement;
console.log(target);
if (target.parentElement.className.indexOf('has-submenu') > -1) {
e.target.classList.toggle('open');
}
}, false);
#menu {
background: #343434;
color: #eee;
height: 35px;
border-bottom: 4px solid #eeeded
}
#menu ul,
#menu li {
margin: 0 0;
padding: 0 0;
list-style: none
}
#menu ul {
height: 35px
}
#menu li {
float: left;
display: inline;
position: relative;
font: bold 12px Arial;
text-shadow: 0 -1px 0 #000;
border-right: 1px solid #444;
border-left: 1px solid #111;
text-transform: uppercase
}
#menu li:first-child {
border-left: none
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
color: #eee;
}
#menu li:hover > a,
#menu li a:hover {
background: #111
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 35px;
opacity: 0;
cursor: pointer
}
#menu label {
font: bold 30px Arial;
display: none;
width: 35px;
height: 36px;
line-height: 36px;
text-align: center
}
#menu label span {
font-size: 12px;
position: absolute;
left: 35px
}
#menu ul.menus {
height: auto;
width: 180px;
background: #111;
position: absolute;
z-index: 99;
display: none;
border: 0;
}
#menu ul.menus li {
display: block;
width: 100%;
font: 12px Arial;
text-transform: none;
}
#menu li:hover ul.menus {
display: block
}
#menu a.home {
background: #c00;
}
#menu a.prett {
padding: 0 27px 0 14px
}
#menu a.prett::after {
content: "";
width: 0;
height: 0;
border-width: 6px 5px;
border-style: solid;
border-color: #eee transparent transparent transparent;
position: absolute;
top: 15px;
right: 9px
}
#menu a.prett.open::after {
content: "";
width: 0;
height: 0;
border-width: 6px 5px;
border-style: solid;
border-color: transparent transparent #eee transparent;
position: absolute;
top: 9px;
right: 9px
}
#menu ul.menus a:hover {
background: #333;
}
#menu ul.menus .submenu {
display: none;
position: absolute;
left: 180px;
background: #111;
top: 0;
width: 180px;
}
#menu ul.menus .submenu li {
background: #111;
}
#menu ul.menus .has-submenu a.open ~ .submenu {
display: block;
}
<nav>
<ul id='menu'>
<li><a class='home' href='/'>Home</a></li>
<li><a class='prett' href='#' title='Menu'>Menu</a>
<ul class='menus'>
<li class='has-submenu'><a class='prett' title='Dropdown 1'>Dropdown 1 + Sub Menu</a>
<ul class='submenu'>
<li>Sub Menu</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
</ul>
</li>
<li><a href='#' title='Dropdown 2'>Dropdown 2</a></li>
<li><a href='#' title='Dropdown 3'>Dropdown 3</a></li>
</ul>
</li>
</ul>
</nav>
let arrow = document.querySelectorAll(".arrow");
for (var i = 0; i < arrow.length; i++) {
arrow[i].addEventListener("click", (e) => {
let arrowParent = e.target.parentElement.parentElement; //selecting main parent of arrow
arrowParent.classList.toggle("showMenu");
});
}
let sidebar = document.querySelector(".sidebar");
let sidebarBtn = document.querySelector(".bx-menu");
console.log(sidebarBtn);
sidebarBtn.addEventListener("click", () => {
sidebar.classList.toggle("close");
});
/* Google Fonts Import Link */
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 300px;
background: #11101d;
z-index: 100;
transition: all 0.5s ease;
}
.sidebar.close {
width: 78px;
}
.sidebar .logo-details {
height: 60px;
width: 100%;
display: flex;
align-items: center;
}
.sidebar .logo-details i {
font-size: 30px;
color: #fff;
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
}
.sidebar .logo-details .logo_name {
font-size: 22px;
color: #fff;
font-weight: 600;
transition: 0.3s ease;
transition-delay: 0.1s;
}
.sidebar.close .logo-details .logo_name {
transition-delay: 0s;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links {
height: 100%;
padding: 30px 0 150px 0;
overflow: auto;
}
.sidebar.close .nav-links {
overflow: visible;
}
.sidebar .nav-links::-webkit-scrollbar {
display: none;
}
.sidebar .nav-links li {
position: relative;
list-style: none;
transition: all 0.4s ease;
}
.sidebar .nav-links li:hover {
background: #1d1b31;
}
.sidebar .nav-links li .iocn-link {
display: flex;
align-items: center;
justify-content: space-between;
}
.sidebar.close .nav-links li .iocn-link {
display: block
}
.sidebar .nav-links li i {
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
color: #fff;
font-size: 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.sidebar .nav-links li.showMenu i.arrow {
transform: rotate(-180deg);
}
.sidebar.close .nav-links i.arrow {
display: none;
}
.sidebar .nav-links li a {
display: flex;
align-items: center;
text-decoration: none;
}
.sidebar .nav-links li a .link_name {
font-size: 15px;
font-weight: 300;
color: #fff;
transition: all 0.4s ease;
}
.sidebar.close .nav-links li a .link_name {
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li .Menu {
padding: 6px 6px 14px 80px;
margin-top: -10px;
background: #1d1b31;
display: none;
}
.sidebar .nav-links li.showMenu .Menu {
display: block;
}
.sub-menu2 {
display: none;
}
.hover-me:hover .sub-menu2 {
display: block;
}
.sidebar .nav-links li .Menu a {
color: #fff;
font-size: 14px;
padding: 5px 0;
white-space: nowrap;
opacity: 0.6;
transition: all 0.3s ease;
}
.sidebar .nav-links li .Menu a:hover {
opacity: 1;
}
.sidebar.close .nav-links li .Menu {
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 10px 20px;
border-radius: 0 6px 6px 0;
opacity: 0;
display: block;
pointer-events: none;
transition: 0s;
}
.sidebar.close .nav-links li:hover .Menu {
top: 0;
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
}
.sidebar .nav-links li .Menu .link_name {
display: none;
}
.sidebar.close .nav-links li .Menu .link_name {
font-size: 15px;
opacity: 1;
display: block;
}
.sidebar .nav-links li .Menu.blank {
opacity: 1;
pointer-events: auto;
padding: 3px 20px 6px 16px;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li:hover .Menu.blank {
top: 50%;
transform: translateY(-50%);
}
.sidebar .profile-details {
position: fixed;
bottom: 0;
width: 260px;
display: flex;
align-items: center;
justify-content: space-between;
background: #1d1b31;
padding: 12px 0;
transition: all 0.5s ease;
}
.sidebar.close .profile-details {
background: none;
}
.sidebar.close .profile-details {
width: 78px;
}
.sidebar .profile-details .profile-content {
display: flex;
align-items: center;
}
.sidebar .profile-details img {
height: 52px;
width: 52px;
object-fit: cover;
border-radius: 16px;
margin: 0 14px 0 12px;
background: #1d1b31;
transition: all 0.5s ease;
}
.sidebar.close .profile-details img {
padding: 10px;
}
.sidebar .profile-details .profile_name,
.sidebar .profile-details .job {
color: #fff;
font-size: 15px;
font-weight: 300;
white-space: nowrap;
}
.sidebar.close .profile-details i,
.sidebar.close .profile-details .profile_name,
.sidebar.close .profile-details .job {
display: none;
}
.sidebar .profile-details .job {
font-size: 12px;
}
.home-section {
position: relative;
background: #E4E9F7;
height: 100vh;
left: 260px;
width: calc(100% - 260px);
transition: all 0.5s ease;
}
.sidebar.close~.home-section {
left: 78px;
width: calc(100% - 78px);
}
.home-section .home-content {
height: 60px;
display: flex;
align-items: center;
}
.home-section .home-content .bx-menu,
.home-section .home-content .text {
color: #11101d;
font-size: 35px;
}
.home-section .home-content .bx-menu {
margin: 0 15px;
cursor: pointer;
}
.home-section .home-content .text {
font-size: 26px;
font-weight: 600;
}
#media (max-width: 400px) {
.sidebar.close .nav-links li .sub-menu {
display: none;
}
.sidebar {
width: 78px;
}
.sidebar.close {
width: 0;
}
.home-section {
left: 78px;
width: calc(100% - 78px);
z-index: 100;
}
.sidebar.close~.home-section {
width: 100%;
left: 0;
}
}
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-collection'></i>
<span class="link_name">Patient Information Module</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="Menu">
<li><a class="link_name" href="#">Patient Information</a></li>
<li>Patient</li>
<li>Dental</li>
<li>Immunization</li>
<li class="hover-me"><a href="#">Pediatric
<i class='bx bxs-chevron-down arrow' ></i>
</a>
<ul class="sub-menu2">
<li><a class="link_name" href="#">Pediatric</a></li>
<li>Immunization</li>
<li>Deworming</li>
<li>Vitamins/Suppliments</li>
</ul>
</li>
<li>TB Dots</li>
<li class="hover-me"><a href="#">OB
<i class='bx bxs-chevron-down arrow' ></i>
</a>
<ul class="sub-menu2">
<li><a class="link_name" href="#">OB</a></li>
<li>Pre-Natal</li>
<li>Post-Natal</li>
<li>Family Planning</li>
</ul>
</li>
</ul>
</li>
This is my updated code

Collapse animation when stop :hover

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>

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>

an anchor tag <a> cannot be clicked in a pure css dropdown menu

When I click on the links in the dropdown menu, it doesn't go any where. It just hided the drop down menu.
What am I doing wrong?
demo
.profile {
float: right;
margin-top: 50px;
margin-right: 20px;
}
.nav- {
/*margin: 0;
padding: 0;*/
list-style-type: none;
}
.nav- li a {
color: #f00;
}
profile .dropdown > a {
line-height: 80px;
}
.dropdown a:focus {
color: #00f;
}
.dropdown-container {
position: absolute;
top: 130px;
right: 0px;
max-height: 0;
overflow: hidden;
background: #FFFFFF;
color: #fff;
box-shadow: 0px 0px 2px #FFFFFF;
}
.dropdown a:focus ~ .dropdown-container {
max-height: 500px;
transition: max-height 0.5s ease-in;
-webkit-transition: max-height 0.5s ease-in;
-moz-transition: max-height 0.5s ease-in;
}
.dropdown-menu li a {
display: inline-block;
min-width: 200px;
padding: 15px 20px;
border-bottom: 1px solid #333333;
color: #CCCCCC;
background-color: #171717;
}
.dropdown-menu li a:hover {
color: #FFFFFF;
background: #030303;
}
<body>
<div class="profile">
<ul class="nav-">
<li class="dropdown">Dropdown Menu <i class="fa fa-angle-down"></i>
<div class="dropdown-container">
<ul class="dropdown-menu">
<li>Help <i class="fa fa-question-circle pull-right"></i>
</li>
<li>Log out <i class="fa fa-sign-out pull-right"></i>
</li>
</ul>
</div>
</li>
</ul>
</div>
</body>

How I make my Dropdown Menu Fade-In Using CSS

#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>