在CSS的文本的彩虹梯度

Eri*_*EMO 24 css css3

在CSS中实现这种设计的最佳方法是什么?

在此输入图像描述

还有这个: 在此输入图像描述

谢谢你的帮助!

Com*_*ide 36

以下是如何创建基本彩虹线性渐变(尚未与文本集成):

#grad1 {
    height: 200px;
    background: red; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(left, orange , yellow, green, cyan, blue, violet); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(right, orange, yellow, green, cyan, blue, violet); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(right, orange, yellow, green, cyan, blue, violet); /* For Firefox 3.6 to 15 */
    background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet); /* Standard syntax (must be last) */
}
Run Code Online (Sandbox Code Playgroud)
<div id="grad1"></div>
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用其中一个梯度生成器(我更喜欢这个).

这是文本集成:

#grad1 {
    background: red;
    background: -webkit-linear-gradient(left, orange , yellow, green, cyan, blue, violet);
    background: -o-linear-gradient(right, orange, yellow, green, cyan, blue, violet);
    background: -moz-linear-gradient(right, orange, yellow, green, cyan, blue, violet);
    background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 20vw;
}
Run Code Online (Sandbox Code Playgroud)
<h1 id="grad1">Fake Text</h1>
Run Code Online (Sandbox Code Playgroud)

这里主要部件background-cliptext-fill-color性能,但要准备好,不是所有的浏览器都支持它.有关浏览器兼容性的更多信息,请检查这些页面底部附近具有相同名称的部分:

背景素材

文本的填充色


小智 10

如果你需要相同的文本渐变使用这样的东西.

    h1 {
  background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 60px;
  line-height: 60px;
}
Run Code Online (Sandbox Code Playgroud)
<h1>100% Unicorn</h1>
Run Code Online (Sandbox Code Playgroud)

但Internet Explorer中不支持text-fill-color.所以也许最好在前台使用透明的png或svg.


Hai*_*inh 5

在 CSS 文件中:

.rainbow {
  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) );

background-image: 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;

border: 2px dotted white;

-webkit-background-clip: text;

background-clip: text;

}
Run Code Online (Sandbox Code Playgroud)

结果

在此处输入图片说明