如何在悬停时使CSS动画反转?

Yes*_*old 2 html css animation css3

我的网站上有一个动画,从width: 100px to 800px悬停时开始.

但是当它悬停时,它只会进入正常位置而没有动画.

我怎么能得到它所以动画会像悬停时那样回到悬停状态?

我只找到过渡的解决方案,但我需要它用于动画.

<div id="blackbox"/>
<div id="blacktxt">
Navigation
</div>
Run Code Online (Sandbox Code Playgroud)

看这里

Yot*_*mer 9

为什么不使用转换而不是动画?工作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;
}
Run Code Online (Sandbox Code Playgroud)