Animated html5 buttons on press

roxics picture roxics · Jul 1, 2011 · Viewed 8.7k times · Source

I'm wondering if there is a way I can animate a button when it is pressed (NOT rolled over) using HTML5/javascript?

I want to create an almost cartoonish button that expands a little when pressed and sparkles. I know that sounds kinda gawdy but I think the final result would look better than it sounds.

My inspiration is the ? blocks in the new Super Mario Brothers games.

Answer

Gaurav picture Gaurav · Jul 2, 2011

What you are looking for is created by CSS3, not HTML5.

Here's a blog post with links to ten different tutorials on making all sorts of cool buttons with CSS3: http://www.catswhocode.com/blog/top-10-css3-buttons-tutorials.

Many of the buttons expand and stuff when rolled over by using the :hover selector. If you want a style to be applied when pressed, just substitute the :active selector instead.

Hope this gets you started.