1
我正在使用来自this website的sass片段来创建颜色堆栈。函数无法返回值
$color-stack:
(group: foo, id: normal, color: #e67835),
(group: foo, id: pale, color: #f8a878),
(group: foo, id: dark, color: #ad490c),
(group: bar, id: normal, color: #426682);
// Color Function
@function color($group, $shade:normal, $transparency:1){
@each $color in $color-stack{
$c-group: map-get($color, group);
$c-shade: map-get($color, id);
@if($group == map-get($color, group) and $shade == map-get($color, id)){
@return rgba(map-get($color, color), $transparency);
}
}
}
在我的代码后来我想用@each
给某些元素不同的颜色取决于他们的父类
@each $category in foo, bar {
.cat-#{$category} {
.some-class {
background-color: color(#{$category}, pale);
}
}
}
我希望它可以编译为:
.cat-foo .some-class {
background-color: #f8a878; //the value of foo pale on the $color-stack map
}
相反它抛出错误:Function color did not return a value
如果我r将#{$category}
替换为字符串foo
,它按预期工作。
工作,谢谢! – ithil