Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用纯CSS生成随机颜色(无javascript)?_Css_Random_Colors - Fatal编程技术网

使用纯CSS生成随机颜色(无javascript)?

使用纯CSS生成随机颜色(无javascript)?,css,random,colors,Css,Random,Colors,是否可以使用纯CSS而不使用javascript生成随机颜色?这可能是不可能的,但我还是很好奇 我为您找到了一些东西,但它使用PHP。我认为使用简单的CSS是不可能的。不太可能。只有在脚本的支持下才能实现动态性。根据本网站, <body style='background-color:<?php printf( "#%06X\n", mt_rand( 0, 0x222222 )); ?>'> 这是可能的,但不是纯css这在纯css中是不可能的 但是,使用诸如SASS()

是否可以使用纯CSS而不使用javascript生成随机颜色?这可能是不可能的,但我还是很好奇

我为您找到了一些东西,但它使用PHP。我认为使用简单的CSS是不可能的。

不太可能。只有在脚本的支持下才能实现动态性。

根据本网站,
<body style='background-color:<?php printf( "#%06X\n", mt_rand( 0, 0x222222 )); ?>'>

这是可能的,但不是纯css

这在纯css中是不可能的

但是,使用诸如SASS()或LESS()之类的预处理器可以为您生成随机颜色,因为它们是使用脚本语言构建的


一个可能在将来帮助读者的侧记是使用的可能性。我们可以通过以下方式声明CSS变量

element {
  --main-bg-color: brown;
}
并像这样使用它:

element {
  background-color: var(--main-bg-color);
}
现在我们可以使用JS进行更改:

// From http://stackoverflow.com/a/5365036/2065702
var randomColor = "#"+((1<<24)*Math.random()|0).toString(16); 

document.documentElement.style.setProperty('main-bg-color', randomColor);
//来自http://stackoverflow.com/a/5365036/2065702

var randomColor=“#”+((1不完全随机,但使用CSS:

步骤1-选择查询的背景,按顺序排列并调整频率

    @keyframes bgrandom {
    0% { background: linear-gradient(90deg, rgba(255,255,255,0.98) 50%, rgba(255,255,255,0.96) 0%); }
    50% { background: linear-gradient(90deg, rgba(255,255,255,0.98) 50%, rgba(255,255,255,0.96) 0%); }

    55% { background: linear-gradient(90deg,  rgba(255,255,255,0.96) 50%, rgba(255,255,255,0.98) 0%); }
    80% { background: linear-gradient(90deg, rgba(255,255,255,0.96)  50%, rgba(255,255,255,0.98) 0%); }

    85% { background: linear-gradient(90deg, rgba(255,255,255,0.96) 50%, rgba(255,255,255,0.94) 0%); }
    100% { background: linear-gradient(90deg, rgba(255,255,255,0.96) 50%, rgba(255,255,255,0.94) 0%); }
    }
步骤2-启动动画(长度动画名称重复模式)

易于使用,定制和工程伟大。
类似的技术可以用于滑块、微调器等。

这是不可能的。CSS几乎是静态的。@Blender实际上不是纯CSS。@Boaz:不是纯CSS,但它已经尽可能接近了。你做了什么吗?和使用PHP差不多,只是这次他们使用的是Ruby。没有颜色变化,有什么帮助吗?@sanojl一味的帮助是不可能的。你可能应该就你的问题提出一个新的问题,包括一个新的问题。
    #element{  animation: 1.2s bgrandom infinite; }