tags:

views:

47

answers:

5

I know I can make my button's image bigger when it is focused using a css like:

button image {
    width:64px;
    height:64px;
}

button:focus, button:focus image {
    width:128px;
    height:128px;
}

But, is there a way to make the image grow gradually (like an animation effect)?

+1  A: 

You cant do animation with current css and html alone. I will recommend jquery instead of css. you can do with html5 but as html5 is not supported by all browsers.

JapanPro
CSS is not HTML 5!
David Dorward
i mean to say : you can do with html5 but as html5 is not supported by all browsers
JapanPro
No, you can do it with CSS3. It's really got nothing to do with HTML5 because it's a style change, not a content change.
Alex
@alex how you can show gradual growing effect with css?
JapanPro
Using CSS transitions? i.e in the hover state of an anchor (for example) you could use -webkit-transform: scale(2); would transform an element (on hover) to twice it's normal size - http://www.the-art-of-web.com/css/css-animation/
Alex
@alex "CSS Transitions make this possible, but have only appeared in draft specifications recently so browser support is weak." - David
JapanPro
@JapanPro when you say weak you mean ancient browsers don't support them ;-) latest version of all browsers now support CSS3 transitions (including FF4 an IE9) - but yes, it's not a great narket share at the moment
Alex
+3  A: 

CSS Transitions make this possible, but have only appeared in draft specifications recently so browser support is weak.

As this is a cosmetic effect, I would probably be happy with the limited support. YMMV, so if you aren't then you will need to look to JavaScript to achieve this. There are various libraries that make animation easier.

David Dorward
I love that you referenced the YUI library, was expecting the jQuery reference to come first! I'm with you, but just in case http://jquery.com/
Alex
Thanks! I'll use it for Firefox, there's more [here](https://developer.mozilla.org/en/CSS/CSS_transitions/).
Tom Brito
A: 

I did this once using an animated .gif as the focusing image (and a reverse animated .gif to go back). It worked ok but was prone to choppiness when a mouse appeared over the link briefly.

Joel Etherton
If I could make the gif animation happen a single time and stop when the image were large, it could work..
Tom Brito
@Tom Brito - I think you would need javascript to accomplish that.
Joel Etherton
A: 

If you want to do this in CSS (as implied in the question), you can do so using CSS Transitions. This is often mistakenly referred to as being part of HTML5 - it isn't; it's part of CSS. But the distinction is often blurred as they are both new and support for them is being brought into browsers together.

If you are considering using CSS Transitions though, it is important to know that they are very new and only have very limited support - ie only in one or two browsers, and even then not necessarily all features, or even properly compatible between browsers.

So if you want something that will be reliable, and will work in all current browsers, then you can't really use CSS. Your best bet would be to use a JQuery - this sort of thing is pretty easy in JQuery, and it works in every browser in use today.

Spudley
A: 

Most recent browsers, except IE, support what you need from CSS Transitions and CSS Transforms.

Webkit based browsers, Firefox and Opera support what you need. The only platform I don't know the status of is IE9, so if you're creating a plain old webside you're out of luck.

Have a look at:

If you have to cater to Internet Explorer take a look at:

thomasmalt