css 文字 渐变 + 描边设置
xiao
2026-11-26 19:19 · 185字 · 2 次浏览
伪元素方案
.tab-item {
display: flex;
align-items: center;
// 未选中(设计稿 1:18 / 1:19):Anton 32 + #CE6FB6 53%→#EE3722 85%
// 伪元素叠加:元素自身 = 底层(实心白字 + 6rpx 居中描边),::after = 顶层渐变字。
// 渐变被裁到字形内,盖住底层描边的内 3rpx,只露出外侧 3rpx,
// 即设计稿 Stroke: Outside / Weight 3 的效果
.tab-txt {
position: relative;
display: inline-block;
font-family: 'Anton-Regular';
font-size: 32rpx;
white-space: nowrap;
color: #FFF6E5;
-webkit-text-stroke: 6rpx #FFF6E5;
&::after {
content: attr(data-text);
position: absolute;
left: 0;
top: 0;
z-index: 1;
white-space: nowrap;
-webkit-text-stroke: 0;
background: linear-gradient(0deg, #CE6FB6 53%, #EE3722 85%);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
}
// 选中态(设计稿 1:10 / 1:13):36 + #9800B1 53%→#FF4266 85%,描边由底层继承字号
&.tab-item-active .tab-txt {
font-size: 36rpx;
&::after {
background-image: linear-gradient(0deg, #9800B1 53%, #FF4266 85%);
}
}
}
- 最终效果
