Sass Map动态按键

时间:2018-11-01 11:57:42

标签: sass sass-maps

是否可以使用变量作为键来定义地图?

示例代码

$types: (
        'INPUT': 1,
        'SELECT': 2,
        'BUTTON': 3,
);

$colors: (
        $types['INPUT'] : #f44336,
        $types['SELECT']: #2196f3,
        $types['BUTTON']: #9c27b0,
);

1 个答案:

答案 0 :(得分:1)

我发现了怎么做

@function type($key) {
  @return map-get($types, $key);
}

$colors: (
        type('INPUT'): #f44336,
        type('SELECT'): #2196f3,
        type('BUTTON'): #9c27b0,
}