CSS Button Transition (Animation)

withpyaar

with Pyaar

Posted on November 3, 2019

CSS Button Transition (Animation)

Transitions: The transition CSS property specifies the name of the CSS property the transition effect is for. In this case we will be transitioning the transform property. You can transition most properties in CSS, like background, color, etc.

A transition needs a beginning and an end state. Thus, transitioning buttons is a great way to use them. Let's do that below.

The beginning state is div styles for the button, which is 200px wide, 75px in height, along with other CSS properties. Our end state will be a hover, or, when a user hovers over the button.

On hover the button changes its background color and scales down. To scale down we apply a transform property and set its value to scale which is a function of the transform property. Transformation functions can rotate, resize, distort and move an element in 2d or 3d space. In this case we are choosing the scale function to resize the button.


div {
width: 200px;
height: 75px;
border-radius: 50px;
background: #0000FF;
transition: transform .6s .25s ease-out; /* apply transition property to the object (div element) that will be transitioning and set the value to the property to transition */
} 


div:hover {
background: #0F0F94;
transform:scale(.9); /* apply transition effect */
} 

Enter fullscreen mode Exit fullscreen mode

See CodePen here: shorturl.at/gx038

💖 💪 🙅 🚩
withpyaar
with Pyaar

Posted on November 3, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How I Got Better at CSS
css How I Got Better at CSS

October 6, 2020