如何在 CSS3 中通过 hover
实现从左到右的下划线动画?
这是一个非常棘手的问题。
我能想到的唯一解决方案是在:hover
时过渡 border-bottom
或者实际上应该说我正在过渡 border-bottom
、width
和 margin-right
,以使 border-bottom
出现并同时保持链接对齐。
很难解释,所以我做了一个快速示例,它不完美,看起来有点混乱,但至少可以展示我的意思。:-)
HTML
<a href="#">Link</a><a href="#">Link</a>
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;
}