Divi Tutorial – animating button backgrounds

Divi Tutorial – animating button backgrounds

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

Leave a Reply

Your email address will not be published. Required fields are marked *

    New tutorials

    Why no ads?

    Hi, I'm PK, and I maintain and publish content on this site for two reasons.

    1. To give back to the community. I learned so much from people's tutorials and StackOverflow that I wanted to contribute and help others.

    2. To provide a more structured learning experience. People struggle to find the course that guides them from start to finish, based off of real life experience, and my courses provide that.

    The only "ads" I have here are for my own courses, and maybe an affiliate link, but that's it. They fund the website resources and provide more motivation for me to produce better content.

    Any bit of interest helps. Even sharing with your friends, suggesting my courses to your developer or designer, or subscribing to my YT channel, or joining our Discord. Thanks and I'll see you around!

    There's a newsletter!

    Sign up to the newsletter for the occasional updates on courses, products, tutorials, and sales.

    Happy Pride Month!

    Happy Pride Month!

    Pretty simple really.

    Happy pride month to everyone who celebrates it!

    I've been seeing a lot of nasty comments on social media recently, so I wanted to add some extra pixels that lean towards love, empathy, and inclusivity to help balance it out.

    Thanks,
    PK