Button animation in CSS in two steps
Button glow animation is an effective method of making your website look interesting and attractive. In this article, we're going to show you how to create such an animation using CSS properties and keyframes, thanks to which we'll be able to achieve a lively button glare that will further encourage website users to take action.
Step 1: Add an HTML button
To do this, we just need to create a simple HTML button and add a class blick-button
.
<button class="blick-button">Button</button>
If you refresh the page, nothing will happen yet because the second step still needs to be done.
Step 2: Write CSS styles
To create a button blink, you need to add the following code to your website's CSS file:
.blick-button {
position: relative;
overflow: hidden;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.blick-button:before {
content: "";
background-color: rgba(255, 255, 255, 0.5);
height: 100%;
width: 3em;
display: block;
position: absolute;
opacity: 1;
top: 0;
left: -4.5em;
-webkit-transform: skewX(-45deg) translateX(0);
transform: skewX(-45deg) translateX(0);
-webkit-transition: none;
transition: none;
-webkit-animation: moving 3s ease-in-out infinite;
-moz-animation: moving 3s ease-in-out infinite;
-ms-animation: moving 3s ease-in-out infinite;
-o-animation: moving 3s ease-in-out infinite;
-animation: moving 3s ease-in-out infinite;
}
@keyframes moving {
30% {
webkit-transform: skewX(-45deg) translateX(33.5em);
transform: skewX(-45deg) translateX(33.5em);
}
100% {
webkit-transform: skewX(-45deg) translateX(33.5em);
transform: skewX(-45deg) translateX(33.5em);
}
}
To see how the button animation will look like, click here 😉
See the Pen Blick Button by Dmytro Romankov (@DmytroRomankov) on CodePen.
So, button blinking with CSS styles is a simple and effective way to make your buttons more convenient, accessible, and attractive. As you can see, it is quite easy to create such an animation. However, if you still don't succeed, please share your problem with me and I will try to help you.