Outline transition duration issues
https://gyazo.com/9989a2e09cee6d53cbac555ef24d155a
I'm trying to apply a duration on the outline for the start button, for some reason, it has a weird delay, not sure if you can notice. It immediately loads the outline, a bit, then, immediately loads the rest after. It's not smooth. Here's the code:
Anyone know why?
Gyazo
Gyazo Screen Video
4 Replies
is the outline width the same on hover and when not in hover?
You haven't set any transition. Plus I would recommend having the outline there but transparent and then, on hover, changing the color.
Something like this: (don't forget the focus state):
<button class="mt-2 cursor-pointer rounded-md border-none bg-slate-200 px-2 text-[1rem] outline outline-2 outline-transparent transition-[outline] duration-500 hover:outline-blue-400 focus-visible:outline-blue-400">
Thank you, that works. Will try to understand this more.
There are 2 things here:
Firstly, if the element doesn't have an outline initially, you can't transition it from not existing to existing. That is why you need to define it first with a transparent color (for example). This way, on hover (and focus), you can transition the color.
Secondly you hadn't actually added any transition, just the transition duration which, on it's own, does nothing. I used
transition-[outline]
as Tailwind doesn't have a transition utility class that includes "outline" (as far as I know) and using tranistion-all
seemed like overkill for just a single tranistion property.