Search code examples
csstailwind-css

Tailwind underline hover animation


I've spent a day figuring out how to make an animation after hovering over the link by using Tailwind-CSS. Here is the animation I want mine link looks like the video. Sample from Youtube

I have tried using :after, but it didn't work out. Here is my link component => https://codepen.io/qqharry21/pen/xxPwqjQ

I Hope can learn how to fix it, and make it works like the video by Tailwind-CSS, thanks!


Solution

  • You can achieve that in pure tailwind with group max-w-{x} and transition-all, use group-hover on the span so when you pass over the link it start the animation

    <a href="#" class="group text-sky-600 transition duration-300">
    Link
    <span class="block max-w-0 group-hover:max-w-full transition-all duration-500 h-0.5 bg-sky-600"></span>
    </a>