CSS Webkit Transition - Fade out slowly than Fade in

Adam Halasz picture Adam Halasz · Apr 14, 2011 · Viewed 38.4k times · Source

This is what I have:

.box{
    background:#FFF;
    -webkit-transition: background 0.5s;
}

.box:hover{
    background:#000;
}

But this appends to both onmouseover and onmouseout actions, but isn't there a way to control them? Something like:

-wekbkit-transition-IN: background 1s;
-webkit-transition-OUT: background 10s;

Answer

Yoann picture Yoann · Apr 14, 2011

Just redifine your transition in the over pseudo element.

.box{
    background: white;
    -webkit-transition: background 5s;
}
.box:hover{
    background: olive;
    -webkit-transition: background 1s;
}

Look my http://jsfiddle.net/DoubleYo/nY8U8/