2017-05-08 50 views
1

我有這個在我的SASS:如何推薦SASS可變

$colors: (
    primary: #f6861f, 
    secondary: #32db64, 
    danger:  #f53d3d, 
    light:  #f4f4f4, 
    dark:  #222 
); 

如果我使用

.menu-inner .scroll-content{ 
    background: $colors['primary']; 
} 

這是行不通的。我在$colors陣列中如何參考primary

回答

3

你的語法不太對 - 你不能在SASS中使用C風格的關聯數組;您需要改用map-get函數。

在你的榜樣,訪問主色,你這樣做:

.menu-inner .scroll-content { 
    background: map-get($colors, primary); 
} 

有一個在thesearticles上SASS地圖一些更多的信息。