csssasscompass-sass

Accessing specific value from SASS nested list


I have the following sass variable:

$color-config:(     "white":    #FFF, 
                    "black":    #303133
);

and i would like to access the 'black' value (#303133) without make a loop. Something like that:

body
    color: $color-config("black")

(i know, its completely wrong, its just to explain what i want)


Solution

  • You can use SASS's maps to store values inside variables:

    $color-config:(
       white: #FFF, 
       black: #303133
    );
    

    Then use map-get() to access it (see here):

    content: map-get($color-config, white); # will return #FFF
    

    In other words, don't use double quotes " around your variable name.