Menu Hover Slide Effect
by davidxmartins
HTML
<nav>
<ul>
<li> <a href="#">Home</a> </li>
<li> <a href="#">About</a> </li>
<li> <a href="#">Blog</a> </li>
<li> <a href="#">Portfolio</a> </li>
<li> <a href="#">Contact</a> </li>
<li class="animation start-home"></li>
</ul>
</nav>
CSS
@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');
body {
font-family: 'Open Sans', sans-serif;
background: #2c3e50;
}
nav {
position: relative;
width: 590px;
height: 50px;
background: #34495e;
border-radius: 8px;
font-size: 0;
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, .1);
}
ul {
display: contents;
}
nav li {
position: relative;
z-index: 1;
display: inline-block;
text-align: center;
}
nav a {
font-size: 15px;
text-transform: uppercase;
line-height: 50px;
color: white;
text-decoration: none;
}
nav .animation {
position: absolute;
height: 100%;
/* height: 5px; */
top: 0;
/* bottom: 0; */
z-index: 0;
background: #1abc9c;
border-radius: 8px;
transition: all .5s ease 0s;
}
nav li:nth-child(1) {
width: 100px;
}
nav .start-home,
li:nth-child(1):hover~.animation {
width: 100px;
left: 0;
}
nav li:nth-child(2) {
width: 110px;
}
nav li:nth-child(2):hover~.animation {
width: 110px;
left: 100px;
}
nav li:nth-child(3) {
width: 100px;
}
nav li:nth-child(3):hover~.animation {
width: 100px;
left: 210px;
}
nav li:nth-child(4) {
width: 160px;
}
nav li:nth-child(4):hover~.animation {
width: 160px;
left: 310px;
}
nav li:nth-child(5) {
width: 120px;
}
nav li:nth-child(5):hover~.animation {
width: 120px;
left: 470px;
}