DIGGING DEEPER:

In our last tutorial, we created a fairly simple html link/button with a pretty cool color and background-color transition, which showed us a lot about how the new CSS transition property works. Today, we’ll be expanding on the previous tutorial, so if you haven’t checked out “CSS3 Transitions Pt.1”, I suggest you take a look at it to get up to speed. We’ll see how to transition multiple properties, and dive into some animation techniques as well. The source code is available for download at the bottom of this page, but you could start from scratch if you’d like as I’ll be posting all of the code snippets as we go along. Let’s get started!

A BIT OF ANIMATION:

CSS animation is brand spanking new, but we can now use our newfound transitions to help us accomplish some pretty neat things. Our button has undergone a slight makeover, and here’s what the CSS looks like now:

First off, to make it more pretty, we’ve gone from red text to white text in the final phase of the transition. The red was terribly ugly, my apologies. We also went ahead and threw in some rounded corners to make it look more like a button. Secondly, we’ve used a property that we’ll discuss later, transform, to rotate our button slightly, and moved the button to a more central location in our page. Let’s go ahead and animate our button to make it rotate back to its original position, expand slightly, and fade in a drop-shadow. Sound good? Let’s take a look at the code:

In our .link selector, we’ve added the following properties:

  1. -webkit-transform-origin: This sets the origin of our rotation to 0,0. That way it only rotates from the very top left corner.
  2. -webkit-transition-property: This allows us to select multiple properties to transition.
  3. -webkit-transition-duration: Since we’ve selected multiple elements to transition, we need to use the longhand value to set how long the transition will take.
  4. -webkit-transition-timing-function: Describes how the animation will repeat over time.

Lastly, we added a rotate transformation to our .link: hover selector, that way it rotates to the normal position when we’re hovering over it. Now, when we load up the HTML file in the browser and hover over our button, we’ll see it rotate, expand, fade in a back-color, and fade in a drop shadow as well. This was all accomplished with a bit of creativity, and an even smaller bit of CSS. In Part 3, we’ll start from scratch and build a working, small-scale solar system using CSS3. Where today we’ve simply put together a few transitions to look like an animation, our next tutorial will introduce true CSS animation using most of the transitions and transformations we learned today. See you next time!

Download Source Files