HTML css 实现字体渐变颜色

利用CSS中的-webkit-gradient背景渐变属性实现,-webkit-gradient是background的一个属性值,webkit内核的safari、 Chrome的Linear Gradients (线性渐变) 基本语法:background-image:-webkit-gradient(type,x1 y1, x2 y2, from(开始颜色值),to(结束颜色值), [color-stop(偏移量小数,停靠颜色值),…] )。

.colorful{
	width: 250px;
	font-size: 20px;
	background-image: 
	-webkit-gradient( linear, left top, right top, color-stop(0, #f22), 
	color-stop(0.15, #f2f), 
	color-stop(0.3, #22f), 
	color-stop(0.45, #2ff), 
	color-stop(0.6, #2f2),
	color-stop(0.75, #2f2), 
	color-stop(0.9, #ff2), 
	color-stop(1, #f22) );
	color: transparent;
	-webkit-background-clip: text;
	-moz-background-clip: text;
	-ms-background-clip: text
}
<div class='colorful'>十步杀一人,千里不留行。</div>

效果

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
    span {
        background: linear-gradient(to right, red, blue);
        -webkit-background-clip: text;
        color: transparent;
    }
    </style>
</head>
<body>
        <span>字体渐变颜色</span>
</body>
</html>

效果

<h1 style=
"background: linear-gradient(to right, rgb(0, 70, 0), rgb(0, 211, 81));
background-clip: text;
color: transparent;">
  <b>
    <em>Welcome to Meadows Nursery</em>
  </b>
</h1>

效果

参考:
https://blog.csdn.net/qq_42331027/article/details/90611599
https://www.jianshu.com/p/8a5c0f1b8ccf

  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值