我正在尝试从最好的十六进制值中提取单个 r、g、b 值,然后将这些值插入背景渐变中。这个想法是我不必摆弄单个 rgb 值。我正在尝试使用红色(@color)、绿色(@color)、蓝色(@color)函数,但我得到的错误是:错误评估函数rgb
:颜色函数将数字作为参数
@color: #E28141;
.test-gradient (@color, @topalpha, @topstop, @bottomalpha, @bottomstop) {
@red1:red(@color);
@green1:green(@color);
@blue1:blue(@color);
background: linear-gradient(to bottom, rgba(@red1,@green1,@blue1,@topalpha) @topstop,rgba(@red1,@green1,@blue1,@bottomalpha) @bottomstop);
}
Martin 指出,上面的代码实际上是有效的,所以我包含了我正在尝试使用的实际 mixin:
.test-gradient (@color, @topalpha, @topstop, @bottomalpha, @bottomstop) {
@red1:red(@color); @green1:green(@color); @blue1:blue(@color);
background: rgb(@red1,@green1,@blue1);
background: -moz-linear-gradient(top, rgba(@red1,@green1,@blue1,@topalpha) @topstop, rgba(@red1,@green1,@blue1,@bottomalpha) @bottomstop);
background: -webkit-gradient(linear, left top, left bottom, color-stop(@topstop,rgba(@red1,@green1,@blue1,@topalpha)), color-stop(@bottomstop,rgba(@red1,@green1,@blue1,@bottomalpha)));
background: -webkit-linear-gradient(top, rgba(@red1,@green1,@blue1,@topalpha) @topstop,rgba(@@red1,@green1,@blue1,@bottomalpha) @bottomstop);
background: -o-linear-gradient(top, rgba(@red1,@green1,@blue1,@topalpha) @topstop,rgba(@red1,@green1,@blue1,@bottomalpha) @bottomstop);
background: -ms-linear-gradient(top, rgba(@red1,@green1,@blue1,@topalpha) @topstop,rgba(@red1,@green1,@blue1,@bottomalpha) @bottomstop);
background: linear-gradient(to bottom, rgba(@red1,@green1,@blue1,@topalpha) @topstop,rgba(@red1,@green1,@blue1,@bottomalpha) @bottomstop);
}