So far we have looked at CSS gradients as well as CSS animations. We are now going to combine them into a cool and interesting effect. This should be considered experimental and probably shouldn’t be used on any production sites unless you have the proper CSS fallbacks.
We are going to create a simple list where the background animates on the hover event so lets get started with some base markup.
Pretty basic here. Nothing new or fantastic. Let’s also set some base CSS styles.
Now is the time for the gradient. We are going to do a 3 color gradient, two at the ends with a color stop 50% through. The markup looks like this:
linear, left top, right top,
For the animation we are going to want the background gradient to move to the left so we see the right most color. This may seem a little odd because you are thinking you should be already seeing the right most color since the gradient takes up 100% of the width. You are correct. We are going to change that with a new CSS property background-size.
To start the animation we are going to need to declare some sort of movement or change on the hover event. In this case we want the background to move to the left (have a background position of right).
To finish up the animation we actually need it to animate, so on the li we need to add this:
-webkit-transition:1s background-position linear;
-moz-transition:1s background-position linear;
transition:1s background-position linear;