I want to design a horizontal menu with an animated effect that activates when hovering over first-level items. Here is the code snippet:
.nav {
float: right;
}
.nav ul {
list-style: none;
padding: 0;
margin: 0;
}
.nav ul li {
position: relative;
}
.nav > ul > li {
float: left;
margin-left: 30px;
}
.nav ul li a {
text-decoration: none;
display: inline-block;
width: auto;
color: #6E6C6C;
transition: 1s ease;
}
.nav ul ul {
position: absolute;
top: 50%;
left: 50%;
display: none;
width: 110px;
}
.nav ul li a:hover {
color: #000;
transform: translateX(-50%);
}
.nav > ul > li > a {
padding: 15px 20px 15px 20px;
width: auto;
}
.nav ul li:hover > ul {
display: block;
}
If I hover out of the first-level item, it reverts to its initial state. How can I fix this issue? Should I consider using flexbox? Please show me a simple example.