CSS文字颜色渐变IE的不兼容处理

CSS文字颜色渐变IE的不兼容处理

在布局页面做字体颜色渐变时,发现谷歌支持 放到IE就不行了, 后来查资料知道是 background-clip:text的问题 ie不支持。

演示代码:

 div {
            color: transparent;
            display: inline-block;
            font-size: 30px;
            font-family: '微软雅黑';
            background-image: -webkit-linear-gradient(right, green, red);
            background-image: linear-gradient(to right, green, red);
            -webkit-background-clip: text;
        }

效果:

在Google正常显示:

在这里插入图片描述

在IE就变成颜色块了:

在这里插入图片描述

解决办法:通过SVG实现线性渐变,在IE下也可以完美实现效果。

代码块:

 <svg height='auto' width='auto'>
        <defs>
            <linearGradient id="grad" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:green; stop-opacity:1" />
                <stop offset="100%" style="stop-color:red; stop-opacity:1" />
            </linearGradient>
        </defs>
        <text x=0 y=60% fill="url(#grad)" style="font-size:100px;font-weight: bold;">测试文字</text>
    </svg>

效果:

在这里插入图片描述

x1-x2:是x轴变换
y1-y2:是y轴变换
像实例中的就是从上往下渐变
stop-color:是变化的颜色

<stop offset="0%" style="stop-color:green; stop-opacity:1" />
<!-- 可以分多个百分比写  看自己需要情况 自己调 -->

例如:

    <svg height='auto' width='auto'>
        <defs>
            <linearGradient id="grad" x1="10%" y1="20%" x2="100%" y2="100%">
                <stop offset="0%" style="stop-color:blue; stop-opacity:1" />
                <stop offset="30%" style="stop-color:black; stop-opacity:1" />
                <stop offset="60%" style="stop-color:pink; stop-opacity:1" />
                <stop offset="100%" style="stop-color:red; stop-opacity:1" />
            </linearGradient>
        </defs>
        <text x=0 y=60% fill="url(#grad)" style="font-size:100px">我的颜色有很多</text>
    </svg>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萝呗 .

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值