Snippet ini akan membuat animasi background pada menu.
<ul> <li><a href="#"> home <span></span> <span></span> <span></span> <span></span> </a></li> <li><a href="#"> about <span></span> <span></span> <span></span> <span></span> </a></li> <li><a href="#"> services <span></span> <span></span> <span></span> <span></span> </a></li> </ul>
body {
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
font-family: sans-serif;
}
ul {
margin: 0;
padding: 0;
display: flex;
list-style-type: none;
}
ul li a {
display: block;
width: 120px;
height: 40px;
line-height: 40px;
text-align: center;
color: red;
text-transform: capitalize;
text-decoration: none;
position: relative;
transition: all 0.5s;
color: #262626;
}
a:hover {
color: white
}
ul li span {
position: absolute;
width: 100%;
height: 25%;
background-color: #262626;
z-index: -1;
left: 0;
top: 0;
transform: scaleX(0);
transition: all 0.5s;
transform-origin: left;
}
a:hover span{
transform: scaleX(1);
}
span:nth-child(2) {
top: 25%;
transition-delay: 0.15s
}
span:nth-child(3) {
top: 50%;
transition-delay: 0.3s
}
span:nth-child(4) {
top: 75%;
transition-delay: 0.45s
}