CSS SWIPE EFFECT

How to create this nice effect called CSS swipe effect. when we hover over a button, you can see that the hex-color background is swiped from left-to-right or right-to-left on the link until it covers the whole thing.

swipe-animation

Let's start🙂:

  1. HTML Structure:

    • Create an anchor tag with the text "hover me."
<a href="#">hover me</a>
  1. CSS Styles:

    • Style the link:
      • Remove text decoration.
      • Set the text color, font, size, border, and padding.
      • Set the position to relative.
      • Add a transition for all properties over .6 seconds.
a{
     font-size: 1.2rem;
     display: inline-block;
     text-decoration: none;
     text-transform: uppercase;
     border: .1rem solid;
     padding: 1.5rem 3rem;
position: relative;
overflow: hidden;
transition: all .6s;
 }
  1. Swipe Effect:

    • Create a ::before pseudo-element:
      • Make the content empty.
      • Set position: absolute, left: 0, top: 0.
      • Set height: 100%, width: 100%, and a background color (e.g., the same color as the link text).
      • Set z-index to -1 to position it behind the link text.
      • Initially, use transform: translateX(-100%) to hide it to the left (negative value moves left).
 a::before{
     content: '';
     position: absolute;
     top: 0;
     left: 0;
      height: 100%;
     width: 100%;
   background-color: rgb(5, 0, 12);
     z-index: -1;
     transition:all .5s;
     transform: translateX(-100%);
 }
  1. Hover Effect:

    • On hover over the link, change the ::before pseudo-element:
      • Use transform: translateX(0) to bring it back to its original position (smooth transition).
      • Change the text color to white (or any desired color).
 a:hover{
     color: white;
 }
 a:hover::before{
    transform: translateX(0);
 }
  1. Customize the Effect:

    • To change the direction of the swipe:
      • For right-to-left swipe, set transform: translateX(100%).
      • For top-to-bottom swipe, use transform: translateY(-100%).

Feel free to experiment with these values to create various swipe hover effects.

a{
     font-size: 1.2rem;
     display: inline-block;
     text-decoration: none;
     text-transform: uppercase;
     border: .1rem solid;
     padding: 1.5rem 3rem;
position: relative;
overflow: hidden;
transition: all .6s;
 }
 a::before{
     content: '';
     position: absolute;
     top: 0;
     left: 0;
      height: 100%;
     width: 100%;
   background-color: rgb(5, 0, 12);
     z-index: -1;
     transition:all .5s;
     transform: translateX(-100%);
 }
 a:hover{
     color: white;
 }
 a:hover::before{
    transform: translateX(0);
 }

See Demo: Codepen