我想创建一个CSS过渡效果,在
我找到的是一个CSS解决方案,其中
:hover
时,a href
元素的border-bottom
扩展到链接的宽度。我找到的是一个CSS解决方案,其中
background width
被动画化:http://jsfiddle.net/mfn5nefb/82/
但这不是我想要的,因为在导航标签上单击后,我希望保留边框。所以我必须直接动画化边框,而不是背景。<!-- assume the border-bottom is only applied to an active=clicked navigation tab -->
<h1 style="border-bottom: 3px solid green;">CSS IS AWESOME</h1>
h1 {
color: #666;
position: relative;
display: inline-block;
}
h1:after {
position: absolute;
left: 50%;
content: '';
height: 40px;
height: 5px;
background: #f00;
transition: all 0.5s linear;
width: 0;
bottom: 0;
}
h1:hover:after {
width: 270px;
margin-left: -135px;
}
在这里,您可以看到“活动”链接会出现绿色边框。当鼠标悬停时,我希望其他选项卡也能进行动画效果,但仅限于边框本身。目前,背景是被动画的,它出现在边框之上,因此看起来不对齐。