CSS彩虹渐变循环动画

Pea*_*ams 3 css colors linear-gradients

正在尝试找到一种方法来创建 CSS 彩虹条纹动画循环...与此类似:

彩虹色环

目前只能创建彩虹条纹的图像,但现在知道如何使用 CSS 创建连续的动画,就像 gif 中一样。

background: linear-gradient(-45deg, rgba(255,0,0,1) 0%, rgba(255,154,0,1) 10%, rgba(208,222,33,1) 20%, rgba(79,220,74,1) 30%, rgba(63,218,216,1) 40%, rgba(47,201,226,1) 50%, rgba(28,127,238,1) 60%, rgba(95,21,242,1) 70%, rgba(186,12,248,1) 80%, rgba(251,7,217,1) 90%, rgba(255,0,0,1) 100%);
Run Code Online (Sandbox Code Playgroud)

图片: 在此输入图像描述

谢谢阅读。

Tem*_*fif 6

您可以尝试如下所示:

html {
  min-height:100%;
  background: 
   linear-gradient(rgba(255,0,0,1) 0%, rgba(255,154,0,1) 10%, rgba(208,222,33,1) 20%, rgba(79,220,74,1) 30%, rgba(63,218,216,1) 40%, rgba(47,201,226,1) 50%, rgba(28,127,238,1) 60%, rgba(95,21,242,1) 70%, rgba(186,12,248,1) 80%, rgba(251,7,217,1) 90%, rgba(255,0,0,1) 100%) 
   0 0/100% 200%;
   animation: a 2s linear infinite;
}

@keyframes a {
  to {background-position:0 -200%}
}
Run Code Online (Sandbox Code Playgroud)

  • 对于那些需要“水平”方式彩虹的人,只需使用“向右”作为“线性梯度()”的第一个参数,即。`线性渐变(向右,rgba(255,0,0,1) 0%,...)` (2认同)
  • @ino这还不够,我们只需要将位置更新为-200% 0,将大小更新为200% 100% (2认同)