CSS 渐变内渐变
CSS Gradients Inside Gradients
是否可以使用渐变作为渐变中的一种颜色?
为了我的特定目的,我有一个从左到右的初始渐变:
linear-gradient(to right, red, darkgray);
但我希望深灰色部分实际上是从上到下的渐变:
linear-gradient(to bottom, darkgray, white);
我尝试了我期望的代码:
linear-gradient(to right, red, linear-gradient(to bottom, darkgray, white));
但这好像行不通,也没见有人写过渐变中渐变的可能性。
编辑:不可能 [CSS 渐变是图像,不能用作其他渐变中的颜色],但@hungerstar 在下面有一个很好的解决方法:用透明胶片分层渐变在另一个梯度上。
不,那不可能。
linear-gradient(
[ <angle> | to <side-or-corner> ,]? <color-stop> [, <color-stop>]+ )
\---------------------------------/ \----------------------------/
Definition of the gradient line List of color stops
where <side-or-corner> = [left | right] || [top | bottom]
and <color-stop> = <color> [ <percentage> | <length> ]?
并且 linear-gradient 不创建颜色,它创建图像。
渐变内的渐变是不可能的。
话虽如此,看看这个。由于渐变是分层的,因此您必须使用 rgba()
为您的颜色设置一些透明度,以允许从后面的渐变通过从上面的渐变显示出来。
也许是这样的?
body {
margin: 0;
height: 100vh;
background:
linear-gradient( to right, rgba(255, 0, 0, 0.5), rgba( 169, 169, 169, 0.5 ) ),
linear-gradient( to bottom, darkgray, white );
}
是否可以使用渐变作为渐变中的一种颜色?
为了我的特定目的,我有一个从左到右的初始渐变:
linear-gradient(to right, red, darkgray);
但我希望深灰色部分实际上是从上到下的渐变:
linear-gradient(to bottom, darkgray, white);
我尝试了我期望的代码:
linear-gradient(to right, red, linear-gradient(to bottom, darkgray, white));
但这好像行不通,也没见有人写过渐变中渐变的可能性。
编辑:不可能 [CSS 渐变是图像,不能用作其他渐变中的颜色],但@hungerstar 在下面有一个很好的解决方法:用透明胶片分层渐变在另一个梯度上。
不,那不可能。
linear-gradient(
[ <angle> | to <side-or-corner> ,]? <color-stop> [, <color-stop>]+ )
\---------------------------------/ \----------------------------/
Definition of the gradient line List of color stops
where <side-or-corner> = [left | right] || [top | bottom]
and <color-stop> = <color> [ <percentage> | <length> ]?
并且 linear-gradient 不创建颜色,它创建图像。
渐变内的渐变是不可能的。
话虽如此,看看这个。由于渐变是分层的,因此您必须使用 rgba()
为您的颜色设置一些透明度,以允许从后面的渐变通过从上面的渐变显示出来。
也许是这样的?
body {
margin: 0;
height: 100vh;
background:
linear-gradient( to right, rgba(255, 0, 0, 0.5), rgba( 169, 169, 169, 0.5 ) ),
linear-gradient( to bottom, darkgray, white );
}