I have the following element:
<div dir="rtl" class="aspect-ratio-1 group relative h-min w-full max-w-[300px] flex-shrink-0 lg:max-w-[390px]">
<img class="rounded-s-full border-[12px] border-indigo-400" alt="Placeholder" src="https://placehold.co/400x600" />
</div>
And I’m looking to create an animation sequence with Tailwind.
For the sequence, first rounded-s-full
should take 0.3 seconds to apply in smooth fashion and after that, border-[12px]
should take 0.3 seconds to "grow". I wonder if this can be achieved with Tailwind. In the documentation I was only able to find how you can apply transitions to specific properties and I could find anything to delay animations.
2
Answers
you can create animation sequences by defining custom CSS classes and using the transition property to specify the duration of the transitions. You can also use the delay property to delay animations.
In your CSS (you can either add this to your existing CSS file or use a tool like @apply with PostCSS if you’re using Tailwind CSS with PostCSS), define the animation classes
Alternatively, you could do this the "Tailwind way" by extending the theme configuration. Specifically, add to the
keyframes
andanimation
properties:Then call on the animation with the
animation-semicircle
class:Unfortunately it’s not possible to reliably animate to the "full" border radius – Tailwind uses a kind-of hack by specifying the full border radius as
9999px
. Attempting to have CSS animate a border radius from 0px to 9999px in 0.3s, as you can imagine, results in a very quick snap.References: