How to increase the duration of pseudo classes in CSS?
Hey! I'm looking to increase the duration that a button remains active after being clicked, so the effect doesn't disappear immediately. I've developed an approach that works well with just two states, but I want to ensure that the delay applies only to the active state and not to the others. For instance, I want the hover state to be immediate, without any delay
11 Replies
You want delay ON the active state but not on hover? Bc your code suggests the opposite, that you want 0ms delay on active and 300ms delay otherwise.
I want the active state to last longer. My code works well with just two states. If I'd add hover state, it will delay there too
That’s because you’ve added the delay to the button , not button::active so if it’s on the button it will apply to all states unless it’s been overwritten. The active state to last longer is the duration , delay just prevents the transition from starting.
Could you please lmk clearly what you want to happen during each state ? Your post and comment has some conflicting information.
For example something like:
1. hover state
-no transition duration , no delay
-immediately on hover bg Color should change to green
2. Active state
-implement transition on the box shadow
-transition duration should be 500ms
-transition should be delayed by 300ms
Etc
Yeah, sorry, maybe I was unclear
button
- some background color
- transition duration 300ms, transition delay 0ms
button:hover
- change background color to a darker one
- transition duration 300ms, transition delay 0ms
button:active
- change the background color to an even darker one
- transition duration 0ms
- before coming back to the idle state it should have a delay of 300ms (i.e. when you release the mouse button it should wait 300ms before changing from #1122bd to #3446eb), so the active effect doesn't disappear immediately after click
Take this code snippet:
This one is missing here:
- before coming back to the idle state it should have a delay of 300ms (i.e. when you release the mouse button it should wait 300ms before changing from #1122bd to #3446eb), so the active effect doesn't disappear immediately after clickHow do I add this effect?
try something like this for no transition on hover but to hold the active state a bit after click is released (this is my undertsanidn of your goal so if thats incorrect, please post a screen recording of the behaviour youre looking for or try to explain again step by step). I havent tested it as im on mobile but maybe it will get you closer. the --vars are called css variables and can hold values as placeholders, and therefore when you change the value, it
or possibly this if the above doesnt work.
I'm trying to achieve similar behavior. As you can see, the active effect doesn't disappear immediately after click, there is a delay before changing from active color to idle color
This one also has a delay on hover, and the one with
:focus
works weirdIll have to test tmrw when I'm on pc to see what's "weird", but it's a hard one because hover state is before/after active, not active back to idle. Depends how you want it to behave then
This one is actually made with some javascript, but I'm looking if it's possible with CSS only
You could instead use custom properties tobswap the bg color with an animation triggered by :active, so when it's Hover state post active the bg colour stays the sane clr as the active was and then at the end of the animation the Hover state reverts back to its original colour.
Javascript would be easiest tbh
You def need a button, not a link that looks like a btn ?😆
is this resolved?
Oh, sorry, didn't see the message. I think I'll stick with this one for now:
Thank you for the help!