css 顺风下划线悬停动画

8aqjt8rx  于 2023-05-19  发布在  其他
关注(0)|答案(3)|浏览(98)

我花了一天的时间来弄清楚如何使用Tailwind-CSS在链接上悬停后制作动画。这里是我想要的动画我的链接看起来像视频。Sample from Youtube
我试过使用:after,但没有成功。这里是我的链接组件=> https://codepen.io/qqharry21/pen/xxPwqjQ
我希望可以学习如何修复它,并使它的作品像视频的Tailwind-CSS,谢谢!

tmb3ates

tmb3ates1#

你可以用组max-w-{x}和transition-all来实现,在跨度上使用组悬停,这样当你经过链接时它就开始动画了

<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>
fcg9iug3

fcg9iug32#

你可以为此过渡:

.link-underline {
        border-bottom-width: 0;
        background-image: linear-gradient(transparent, transparent), linear-gradient(#fff, #fff);
        background-size: 0 3px;
        background-position: 0 100%;
        background-repeat: no-repeat;
        transition: background-size .5s ease-in-out;
    }

    .link-underline-black {
        background-image: linear-gradient(transparent, transparent), linear-gradient(#F2C, #F2C)
    }

    .link-underline:hover {
        background-size: 100% 3px;
        background-position: 0 100%
    }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" integrity="sha512-wnea99uKIC3TJF7v4eKk4Y+lMz2Mklv18+r4na2Gn1abDRPPOeef95xTzdwGD9e6zXJBteMIhZ1+68QC5byJZw==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div class="min-h-screen bg-gray-100 py-6 flex flex-col justify-center sm:py-12">
    <div class="relative py-3 sm:max-w-xl sm:mx-auto">
        <a href="#" class="font-display max-w-sm text-2xl font-bold leading-tight">
            <span class="link link-underline link-underline-black text-black"> Link Hover Effect </span>
        </a>
    </div>
</div>
ifsvaxew

ifsvaxew3#

如果你不想包含一个CSS文件只是为了这个功能,或者你只是想在Tailwind中做这件事-我在下面发布的代码片段纯粹基于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>

欢呼和快乐的编码!

相关问题