css文字裁剪实现渐变

css文字裁剪实现渐变效果

效果图

在这里插入图片描述


<view class="gradient-text">世界如此美妙,你却如此暴躁</view>
<view class="gradient-text-position">世界如此美妙,你却如此暴躁</view>
<view class="gradient-text1">世界如此美妙,你却如此暴躁</view>
<view class="gradient-text2">世界如此美妙,你却如此暴躁</view>

基本使用

.gradient-text {
    color: transparent;
    font-size: 40rpx;
    background: -webkit-linear-gradient(30deg, #32c5ff 25%, #b620e0 50%, #f7b500 75%, #20e050 100%);
    // 兼容
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
}

background-position

  • 使用background-position位置位移
.gradient-text-position {
    font-size: 46rpx;
    color: transparent;
    background: -webkit-linear-gradient(20deg, #32c5ff 25%, #b620e0 50%, #f7b500 75%, #20e050 100%);
    background-clip: text;
    animation: bgPosition 3s infinite linear;
}

@keyframes bgPosition{
    0% {
        background-position: 0;
    }
    100% {
        background-position: 400rpx;
    }
}

filter

  • 使用filter函数的hue-rotate给图像应用色相旋转
.gradient-text1 {
    font-size: 50rpx;
    color: transparent;
    background: linear-gradient(45deg, #ffeb3b, #009688, #ef32d9, #fc67fa, #03a9f4, #9c27b0, #8bc34a);
    background-clip: text;

    // 背景渐变 hue-rotate图像的色调旋转
    animation: huerotate 3s infinite;
}

@keyframes huerotate {
    100% {
        filter: hue-rotate(360deg);
    }
}

background-image

.gradient-text2 {
    font-size: 52rpx;
    color: transparent;
    background: linear-gradient(90deg, #f7797d 0, #CAC531 15%, #F3F9A7 30%, #43C6AC 45%, #12c2e9 60%, #c471ed 75%, #f64f59 90%, #89fffd 100%);
    background-clip: text;
    animation: changeColor .5s linear infinite alternate;
}

@keyframes changeColor {
    0% {
        background-image: linear-gradient(90deg, #f7797d 0, #CAC531 15%, #F3F9A7 30%, #43C6AC 45%, #12c2e9 60%, #c471ed 75%, #f64f59 90%, #89fffd 100%);
    }

    50% {
        background-image: linear-gradient(90deg, #f4c4f3 0, yellowgreen 15%, fuchsia 30%, lime 45%, olive 60%, aqua 75%, #f64f59 90%, #89fffd 100%);
    }

    100% {
        background-image: linear-gradient(-90deg, #f7797d 0, #CAC531 15%, #F3F9A7 30%, #43C6AC 45%, #12c2e9 60%, #c471ed 75%, #f64f59 90%, #89fffd 100%);
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用 CSS 的 text-stroke 属性和 background-clip 属性来实现文字描边和渐变文字的效果。 首先,我们可以使用 text-stroke 属性来设置文字的描边样式,可以通过设置描边的颜色和宽度来实现不同的效果。例如: ```css .text { -webkit-text-stroke: 2px #000; /* 设置描边宽度和颜色 */ color: transparent; /* 将文字设置为透明,只显示描边 */ } ``` 接下来,我们可以使用 background-clip 属性来设置文字的背景裁剪方式,以实现渐变文字的效果。通过设置背景裁剪方式为 text,背景将仅填充文字的区域。例如: ```css .text { background: linear-gradient(to right, #ff0000, #00ff00); /* 设置渐变背景 */ -webkit-background-clip: text; /* 将背景裁剪文字区域 */ color: transparent; /* 将文字设置为透明,只显示背景 */ } ``` 最后,我们将两个效果结合在一起,就可以实现文字描边加渐变文字的效果。例如: ```css .text { -webkit-text-stroke: 2px #000; /* 设置描边宽度和颜色 */ background: linear-gradient(to right, #ff0000, #00ff00); /* 设置渐变背景 */ -webkit-background-clip: text; /* 将背景裁剪文字区域 */ color: transparent; /* 将文字设置为透明,只显示描边和背景 */ } ``` 以上是一种常见的实现方式,不过需要注意的是,由于 text-stroke 和 background-clip 属性的兼容性问题,可能需要添加浏览器厂商前缀来确保在不同浏览器下的兼容性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值