我正在尝试将 linear-gradient
应用于 <a>
的 border-bottom
,但它没有完全生效。我的目标是只用 HTML 和 CSS 实现。
这是我的代码:
a {
font-size: 30px;
text-decoration: none;
color: #666;
cursor: pointer;
padding-right: 3%;
padding-bottom: 3%;
position: relative;
display: inline-block;
}
a:after {
content: '';
position: absolute;
left: -50%;
right: 0%;
border-top: 0;
border-left: 0;
border-right: 0;
border-image: -webkit-linear-gradient(left, #f0f0f0, #0a389b, #f0f0f0);
border-image: -moz-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
border-image: -ms-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
border-image: -o-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
transition: all 0.5s linear;
bottom: 0;
opacity: 0;
}
a:hover:after {
border-right: 25vh;
right: 0%;
opacity: 1;
}
<div>
<a href="#">First</a>
<a href="#">Second</a>
<a href="#">This is the third</a>
</div>
您可以看到,border-bottom
不在中心位置,并且不适合<a>
标签的width
宽度。
background-size
不是可动画/可过渡的属性。在IE11之前,它会优雅地降级并产生没有过渡的边框。在Edge中,它完美地工作。 - Harry