Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a transition for an element losing focus

Tags:

css

I have a simple transition from black to dark grey like so:

.navbar .logo:hover {
    -o-transition: 1s;  
    -ms-transition: 1s;
    -moz-tranistion: 1s;
    -webkit-transition: 1s;
    transition: 0.2s;

    color: darkgrey;

}

Demo: http://jsfiddle.net/yD46F/10/

But when I stop hovering, it instantly turns back to black, instead of transitioning back to black, how can I fix this? Thanks!

like image 345
Datsik Avatar asked Mar 24 '23 04:03

Datsik


1 Answers

Move your transitions to a separate CSS rule:

.navbar .logo {
    -o-transition: 1s;  
    -ms-transition: 1s;
    -moz-tranistion: 1s;
    -webkit-transition: 1s;
    transition: 0.2s;
}

The issue there is that you are currently assigning transitions to an element with pseudo-class :hover. So when the mouse moves from the element, it does not have :hover class anymore => does not have transition style properties.

like image 141
Artyom Neustroev Avatar answered Apr 02 '23 19:04

Artyom Neustroev