解决方案
好的,最后我找到了一种解决方法来实现我的愿望,它几乎都来自 SVG 文件。我稍微调整了我的 SVG,以便获得两条不同的路径,渐变描边但未填充,另一条渐变填充但没有描边。一个在另一个上,不透明度是万能钥匙:)
<a type="button" href="#">
<svg class="icon" viewBox="0 0 250 100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient x1="0%" y1="100%" x2="100%" y2="0%" id="linearGradient-1">
<stop stop-color="#08AEEA" offset="0%"></stop>
<stop stop-color="#2AE88A" offset="100%"></stop>
</linearGradient>
</defs>
<path fill="none" d='M50,95 a45,45 0 0,1 0,-90 h150 a45,45 0 1,1 0,90 h-150' />
<path class="icon--plain" fill="url(#linearGradient-1)" d='M50,95 a45,45 0 0,1 0,-90 h150 a45,45 0 1,1 0,90 h-150' />
</svg>
Invest now
这是CSS(我正在使用SCSS btw):
a[type="button"] {
position: relative;
padding: 1rem 1.75rem;
z-index: 0;
.icon {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
z-index: -1;
path {
transition: opacity 0.4s ease;
&:first-of-type {
fill: transparent;
stroke: url(#linearGradient-1);
stroke-width: 3;
opacity: 1;
}
&.icon--plain {
opacity: 0;
stroke: none;
stroke-width: 0;
}
}
}
&:hover {
path {
&:first-of-type {
opacity: 0;
}
&.icon--plain {
opacity: 1;
}
}
}
}