【发布时间】:2015-05-12 18:03:44
【问题描述】:
使用 SASS,我正在尝试创建一个动态线性渐变,所以如果我有一个颜色数组,我想循环遍历它并将每种颜色添加到渐变中。
@import "compass";
$colors: red green blue;
$numColors: length($colors);
div {
$g: nth($colors, 1);
@for $h from 2 to ($numColors + 1) {
$g: $g , nth($colors, $h);
}
border: $g;
background: linear-gradient($g);
}
这会导致以下错误
At least two color stops are required for a linear-gradient
去掉背景参数会编译,看起来像这样
border: red, green, blue;
(我知道这不是一个有效的边界,我只是想“追踪”出 $g)
如何动态迭代数组并创建线性渐变?
【问题讨论】:
-
您打算使用添加供应商前缀的 compass
linear-gradientmixin,还是使用标准 CSSlinear-gradient?
标签: css sass compass-sass