Skip to content Skip to sidebar Skip to footer

How To Make CSS Animation Reverse On Hover-out?

I have an animation on my site which goes from width: 100px to 800px when hover on. But when hover out, it just goes to the normal position with no animation. How could I get it so

Solution 1:

Why not use transitions instead of animations? Working jsFiddle

#blackbox {
    background: black;
    width: 100px; 
    height: 80px; 
    color: white; 
    text-align: center; 
    font-family: Times; 
    font-size: 20px;
    position: fixed;
    left: 0px;
    bottom: 100px;
    opacity: 0.5;
    margin-bottom: 10px;
    transition: all 2s; /* Add this transition */
}


#blackbox:hover { /* Apply the new design on hover */
    opacity: 0.8;
    width: 800px;
}

#blacktxt {
    margin-top: 10px;
    height: 60px;
    transition: opacity 0.5s, width 5s;
    position: absolute;
    font-family: cursive;
    cursor: default;
}

#blacktxt:hover {
    opacity: 0;
}

Post a Comment for "How To Make CSS Animation Reverse On Hover-out?"