CSS
h2 {
display: inline-block;
background-image: linear-gradient(to right, 颜色1, 颜色2);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
1.将h2块元素转为行内块
2.设置背景渐变色
3.背景剪切蒙版
4.文字改为透明色
tailwindCSS
<h2 className="text-[3.5rem] uppercase font-[700] bg-gradient-to-r from-[rgba(126,213,111)] to-[rgba(40,180,131)] inline-block bg-clip-text text-transparent">
exciting tours for adventurous people
</h2>
// 关键代码
bg-gradient-to-r from-[rgba(126,213,111)] to-[rgba(40,180,131)] // 设置背景渐变色
inline-block // 转换为行内块元素
bg-clip-text // 设置文字剪切蒙版
text-transparent // 设置文字为透明色