方法一 background-clip + text-fill-color
李祺丰·前端
<h2 class="text-gradient" data-text="天赐美妞">天赐美妞</h2>
///与HTML相对应的CSS代码如下:
.text-gradient {
display: inline-block;
font-family: '微软雅黑';
font-size: 10em;
position: relative;
}
.text-gradient[data-text]::after {
content: attr(data-text);
color: green;
position: absolute;
left: 0;
z-index: 2;
-webkit-mask-image: -webkit-gradient(linear, 0 0, 0 bottom, from(#ff0000), to(rgba(0, 0, 255, 0)));
}
方法二 mask-image
支持浏览器是Chrome或是Safari
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>qiphon</title>
<style>
.text-gradient {
display: block;
font-size: 10em;
position: relative;
}
.text-gradient[data-text]::after {
content: attr(data-text);
color: green; ////颜色渐变是根据这里的值变化的
position: absolute;
z-index: 2;
-webkit-mask-image: -webkit-gradient(linear, 0 0, 0 bottom, from(#000), to(rgba(0, 0, 0, 0)));
}
</style>
</head>
<body>
<h2 class="text-gradient" data-text="qiphon--前端"></h2>
</body>
</html>