Maps help you keep related values together in one place. This makes your styles easier to manage and update.
Maps for grouped values in SASS
$map-name: (key1: value1, key2: value2, key3: value3);
Use parentheses () to define a map.
Keys and values are separated by a colon :, and pairs are separated by commas.
$colors: (primary: #3498db, secondary: #2ecc71, danger: #e74c3c);
$font-sizes: (small: 0.8rem, medium: 1rem, large: 1.5rem);
$spacing: (padding: 1rem, margin: 2rem);
This example shows a map called $theme-colors holding three colors. We use map.get() to get colors for different button styles. This keeps colors grouped and easy to change.
@use 'sass:map'; $theme-colors: ( primary: #005f73, secondary: #0a9396, accent: #94d2bd ); .button { background-color: map.get($theme-colors, primary); color: white; padding: 1rem 2rem; border: none; border-radius: 0.5rem; font-size: 1rem; cursor: pointer; } .button-accent { background-color: map.get($theme-colors, accent); color: black; }
You can use map.get() to access values by their keys.
Maps can hold any type of value, including numbers, colors, strings, or even other maps.
Grouping values in maps helps keep your code clean and easy to update.
Maps group related values together for easy management.
Use keys to name values and map.get() to retrieve them.
This makes your styles more organized and easier to maintain.
Practice
maps in Sass?Solution
Step 1: Understand what maps do in Sass
Maps store multiple related values under named keys, making styles organized.Step 2: Compare options with map purpose
Only grouping related values matches the purpose of maps.Final Answer:
To group related values together for easier management -> Option BQuick Check:
Maps group values = C [OK]
- Thinking maps create animations
- Confusing maps with comments
- Believing maps run JavaScript
$colors with keys primary and secondary?Solution
Step 1: Recall Sass map syntax
Sass maps use parentheses with key: value pairs separated by commas.Step 2: Check each option's syntax
$colors: (primary: #ff0000, secondary: #00ff00); uses correct parentheses and colon syntax; others use invalid symbols or brackets.Final Answer:
$colors: (primary: #ff0000, secondary: #00ff00); -> Option AQuick Check:
Maps use (key: value) pairs [OK]
- Using curly braces instead of parentheses
- Using equal sign instead of colon
- Using square brackets instead of parentheses
$theme-colors: (primary: #0055ff, secondary: #ff5500);
What will be the output CSS color for
color: map.get($theme-colors, primary);?Solution
Step 1: Understand map.get() usage
map.get() retrieves the value for the given key from the map.Step 2: Identify the value for key 'primary'
In the map, 'primary' key has value '#0055ff'.Final Answer:
#0055ff -> Option AQuick Check:
map.get returns value for key [OK]
- Confusing key with value
- Expecting the key name as output
- Using map.get syntax incorrectly
$fonts: (heading: 'Arial', body: 'Helvetica'); $main-font: map.get($fonts, 'heading');
Solution
Step 1: Check map key usage in map.get()
In Sass, map keys are identifiers and should not be quoted when used in map.get().Step 2: Verify other options
Keys can be strings or identifiers but quoting keys in map.get() is incorrect; map.get() exists; maps use parentheses.Final Answer:
Keys in map.get() should not be quoted -> Option DQuick Check:
Use unquoted keys in map.get() [OK]
- Quoting keys in map.get()
- Using wrong brackets for maps
- Thinking map.get() is invalid
$button-styles that groups background, color, and border-radius for buttons. Which code correctly defines this map and accesses the color value?Solution
Step 1: Define map with correct syntax
Maps use parentheses with key: value pairs separated by commas; keys are unquoted identifiers.Step 2: Access map value correctly
Use map.get(map, key) with unquoted key to get the value.Final Answer:
$button-styles: (background: #0088cc, color: #ffffff, border-radius: 0.5rem); $btn-color: map.get($button-styles, color); -> Option CQuick Check:
Correct map syntax and unquoted key access [OK]
- Using curly braces or square brackets for maps
- Quoting keys in map.get()
- Using => instead of : in map definition
Ready to prove it?
Pass the test and this pattern moves unknown
