我有一个SASS映射,其中的所有键都有一些重复的值:
$test-h1:(
null: (
font-size: 20px,
color: red,
font-weight: 100
),
small:(
font-size: 30px,
color: yellow,
font-weight: 100
),
medium:(
font-size: 40,
color: orange,
font-weight: 100
),
large:(
font-size: 50px,
color: green,
font-weight: 100
)
);
有没有一种方法可以提取公共值并为所有键继承它们?还是仅使用重复性方法来做,还是使用另一个名为
common
的键并将其添加到所有键中? 最佳答案
不,Sass没有任何此类功能。您必须使用map-merge以编程方式更改映射本身。
$test-h1:(
null: (
font-size: 20px,
color: red
),
small:(
font-size: 30px,
color: yellow
),
medium:(
font-size: 40,
color: orange
),
large:(
font-size: 50px,
color: green
)
);
$common:
(font-weight: 100);
@each $k, $v in $test-h1 {
$test-h1: map-merge($test-h1, ($k: map-merge($v, $common)));
}
关于css - SASS映射是否可以选择为所有键设置公用值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35201717/