CSS transitions do not have any effect on background gradients. As far as I know, the thing is that something similar would be quite difficult to achieve considering the multitude of possible gradients that can be created using a color palette.
Though, there are some simple ways you can simulate smooth transitions on gradients and below you’ll see how to do that.
Before writing this article, I was thinking this new article will hopefully be more useful to you as It contains one more extra technique that can help you faking transitions on background gradients.
So, what is this about and why would you care about transitions on gradients? The answer is very simple: just think about the situation when you’re designing some CSS3 icons/buttons. To make them look awesome, it’s almost mandatory to use shadows, rounded corners and gradients.
Read the workarounds described below and you’ll be able to greatly improve your gradient buttons, especially their
For this demo, we’re using three colored boxes to whom are applied the following workarounds.
I extracted only the important styles needed and as you can see, the
background-color has the most important role, as it’s the one who’s actually being transitioned here.
transition: background-color .2s ease-out;
Having already a transitioned
background-color, you just need to set a semi transparent background using
background-image and the result will be a smooth gradient transition for the element to whom these styles are applied to.
background-image: linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0));
Perhaps this is a bit dirtier, but it’s still a fully working technique. Instead of a semi transparent background as above, this assume using an inset box-shadow:
box-shadow: 0 60px 50px -30px rgba(255, 255, 255, .5) inset;
As you can see, the workarounds above are quite simple and easy to implement. Also, the big advantage is that they don’t require any additional markup element to work.
Thanks for reading and feel free to share your thoughts!
Posted by: Dhiraj kumar