How to create sliding effect on button hover

Learn how to create sliding effect on button hover

  • Home

Create sliding effect on button hover

Step 1: Add HTML Code

<ul>
    <li><span>Home</span></li>
</ul>

Step 2: Add CSS Code

body{
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
ul{
    padding: 0%;
    list-style-type: none;
}
li{
    font-size: 25px;
    width: 8em;
    height: 2em;
    color: var(--primary);
    border-left: 0.08em solid;
    position: relative;
    margin-top: 0.8em;
    cursor: pointer;
}
li::before,li::after{
    content: '';
    position: absolute;
    width: inherit;
    border-left: inherit;
    z-index: -1;
}
li::before {
    height: 80%;
    top: 10%;
    left: calc(-0.15em - 0.08em * 2);
    filter: brightness(0.8);
}
li:after{
    height: 60%;
    top: 20%;
    left: calc(-0.15em * 2 - 0.08em * 3);
    filter: brightness(0.6);
}
li span{
    position: relative;
    height: 120%;
    top: -10%;
    box-sizing: border-box;
    border: 0.08em solid;
    background-color: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: sans-serif;
    text-transform: capitalize;
    transform: translateX(calc(-0.15em * 3 - 0.08em *2));
    transition: 0.3s;
}
li:hover span{
    transform: translateX(0.15em);
}