我想在CSS中为文本的背景色添加线性渐变。我知道线性梯度是图像。以下是我的代码不起作用。还有别的方法可以做到这一点吗?
<h1 style"background-color: linear-gradient(red, yellow);">Linear Gradient - Top to Bottom
请帮帮忙。
发布于 2022-10-08 03:22:18
您不能直接对文本这样做,但是可以使用background-clip来实现这一点。
h2 {
font-size: 30px;
background: linear-gradient(red, yellow);
background-clip: text;
-webkit-text-fill-color: transparent;
}<h2>COLORFUL TEXT</h2>
如果只想为文本背景着色,那么只需添加到文本背景中即可。很简单。不要使用background-color --只需要使用background
h2 {
text-align: center;
background: linear-gradient(red, yellow);
} <h2>COLORFUL TEXT</h2>
https://stackoverflow.com/questions/73993802
复制相似问题