Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 503
hao Avatar asked Dec 09 '25 09:12

hao


2 Answers

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>
like image 58
Aciddiz Avatar answered Dec 12 '25 01:12

Aciddiz


If you're not wanting to include a CSS file just for this functionality or you just want to do it in Tailwind - the code snippet I've posted below is based purely on Tailwind CSS.

<a class="group text-pink-500 transition-all duration-300 ease-in-out" href="#">
  <span class="bg-left-bottom bg-gradient-to-r from-pink-500 to-pink-500 bg-[length:0%_2px] bg-no-repeat group-hover:bg-[length:100%_2px] transition-all duration-500 ease-out">
    This text gets 'underlined' on hover
  </span>
</a>

Cheers and happy coding!

like image 39
Zane Wilson Avatar answered Dec 12 '25 02:12

Zane Wilson



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!