Let’s learn how to make some cool CSS based button animations.
This one’s relatively easy.
Let’s start with the video:
The trick is giving the background a gradient, make it larger than double the button, and aligning the left sides.
Then, on hover, move the background so its right side will align with the right side of the button.
With some clever gradients, you can make some pretty cool effects.
Where do you get the gradient? Just click on any of the cool buttons above. haha
I added the link to the buttons.
Here’s the CSS you see in the video.
.et_pb_button.background-animation { display: inline-block; border-radius: 1px; border: 0px; padding: 10px 17px 10px 20px; letter-spacing: 3px; color: #fff; font-size: .75rem; line-height: 1; text-transform: uppercase; text-align: center; font-weight: 700; background-size: 250% auto; background: rgb(255,183,107); background: -moz-linear-gradient(-45deg, rgba(255,183,107,1) 0%, rgba(255,167,61,1) 50%, rgba(255,252,249,1) 51%, rgba(255,183,107,1) 55%, rgba(255,127,4,1) 100%); background: -webkit-linear-gradient(-45deg, rgba(255,183,107,1) 0%,rgba(255,167,61,1) 50%,rgba(255,252,249,1) 51%,rgba(255,183,107,1) 55%,rgba(255,127,4,1) 100%); background: linear-gradient(135deg, rgba(255,183,107,1) 0%,rgba(255,167,61,1) 50%,rgba(255,252,249,1) 51%,rgba(255,183,107,1) 55%,rgba(255,127,4,1) 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffb76b', endColorstr='#ff7f04',GradientType=1 ); -webkit-transition: all 0.5s ease-in-out; -moz-transition: all 0.5s ease-in-out; -o-transition: all 0.5s ease-in-out; -ms-transition: all 0.5s ease-in-out; transition: all 0.5s ease-in-out; } .et_pb_button.background-animation:hover { background-color: transparent; border-radius: 1px; border: 0px; padding: 10px 17px 10px 20px; background-position: right center; -webkit-transition: all 0.5s ease-in-out; -moz-transition: all 0.5s ease-in-out; -o-transition: all 0.5s ease-in-out; -ms-transition: all 0.5s ease-in-out; transition: all 0.5s ease-in-out; } .et_pb_button.background-animation:after { display: none; }
Note: watch the video for more explanation on which lines can be taken out, or edited. (basically the first blocks, so 2-12, 28-31 can be taken out and styled within the builder as long as you don’t touch the background settings, and 16-20 is what you swap out with your own custom gradient)
So paste that CSS here:
Next add the custom class to the button like this:
And you will be finished.
Please leave a comment if you have any questions!
Here are some other similar tuts you might enjoy
[sc name=”learn css”]
Featured Image Credit: Photo by Ashkan Forouzani on Unsplash