Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use css transition to show fast and hide slow

Tags:

css

animation

I have a span which is set to opacity : 0 and I show it when user hover on it, but the matter is I want to show it fast and hide it again slowly.

.mySpan {
    opacity: 0;
    font-size: 12px;
    background: red;
    border-radius: 5px;
    color:#fff;
    transition: opacity cubic-bezier(0, 0.52, 1, 1) 0.3s
}

.mySpan:hover{
    opacity: 1
}
like image 773
SayJeyHi Avatar asked Dec 21 '25 21:12

SayJeyHi


1 Answers

Override the transition duration on hover:

.mySpan {
    opacity: 0.1;
    font-size: 12px;
    background: red;
    border-radius: 5px;
    color:#fff;
    transition: opacity cubic-bezier(0, 0.52, 1, 1) 1s;
}

.mySpan:hover{
    opacity: 1;
    transition-duration: 200ms;
}
<span class="mySpan">Hello</span>

On hover it shows fast as the duration is 200ms but when you stop hovering it reverts back to 1s and hides slowly.

like image 94
James Coyle Avatar answered Dec 24 '25 16:12

James Coyle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!