You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

鼠标悬停下划线过渡出现粗边框问题及TailwindCSS适配方案

菜单项下划线过渡效果实现问题

问题描述

我想给菜单项实现下划线过渡效果,参考了Stack Overflow上的方案,但拆分border-bottom属性编写CSS后,出现边框过粗且部分提前显示的问题。由于使用TailwindCSS无法使用border-bottom简写属性,需采用拆分写法,期望达到原方案的效果。

原参考方案代码

a { text-decoration: none; display: inline-block; }
a:after {
    content: '';
    display: block;
    border-bottom: 1px solid blue;
    width: 0;
    -webkit-transition: 0.5s ease;
            transition: 0.5s ease;
}
a:hover:after { width: 100%; }
<a>A link with an animated bottom border</a>

我的实现代码

a { text-decoration: none; display: inline-block; }
a:after {
    content: '';
    display: block;
    width: 0px;
    border-bottom-width: 1px;
    border-style: solid;
    border-color: rgb(21 19 25);
   -webkit-transition: 0.5s ease;
            transition: 0.5s ease;
}
a:hover:after { width: 100%; }
<a>A link with an animated bottom border</a>

适配TailwindCSS的解决方案代码

@apply after:block
    after:w-0 
    after:border-0
    after:border-b
    after:border-solid
    after:border-b-blue 
    after:transition-all 
    after:duration-200 
    after:ease-linear
    after:content-[''];

内容的提问来源于stack exchange,提问作者ElbartoTn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 19:10:29