强调css3过渡

zil*_*oid 12 underline css3 css-transitions

如何在CSS3中从左到右创建下划线动画hover

Chr*_*der 23

这是一个非常棘手的问题.

唯一的解决办法我能想出是过渡border-bottom:hover或我其实应该说我过渡border-bottom,widthmargin-rightborder-bottom出现,并在同一时间保持,在这种情况下,链接对齐.

很难解释,所以我做了一个不完美的例子,看起来有点乱,但至少它显示了我的意思.:-)

小提琴

HTML

<a href="#">Link</a><a href="#">Link</a>
Run Code Online (Sandbox Code Playgroud)

CSS

a {
    text-decoration: none;
    display: inline-block;
    border-bottom: 1px solid blue;    
    margin-right: 39px; 
    width: 0px;
    -webkit-transition: 0.5s ease;
            transition: 0.5s ease;
}

a:hover {
    -webkit-transition: 0.5s ease;
            transition: 0.5s ease;
    border-bottom: 1px solid blue;
    width: 30px;
    margin-right: 9px;
}
Run Code Online (Sandbox Code Playgroud)

  • 将宽度设置为0从而使实际内容流出链接可能会对布局的其余部分产生副作用.我建议使用生成的元素(:after),将其绝对定位在链接的底部,而不是为该伪元素的宽度设置动画. (6认同)