css 文字 渐变 + 描边设置

xiao
xiao

伪元素方案

  • 设计稿图
    ScreenShot_2026-11-26_192217_804.png
  • html代码

     <view class="tab-item tab-wheel" >
      <view class="tab-txt" :data-text="i18nTitle.tabWheel">XXXXX</view>
     </view>
  • css 代码
.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%);
        }
    }
}
  • 最终效果
    2222.png
Copyright

原创 本文由 xiao 发布于 xiao。

原文链接:https://blog.joniding.com/index.php/archives/68/

许可协议CC BY-NC-ND 4.0署名-非商业性使用-禁止演绎 4.0 国际

发表评论

0:00