0
0
SASSmarkup~30 mins

Spacing scale generation in SASS - Mini Project: Build & Apply

Choose your learning style9 modes available
Spacing Scale Generation with Sass
📖 Scenario: You are creating a consistent spacing scale for a website using Sass. This scale will help keep margins and paddings uniform across the site.
🎯 Goal: Build a Sass map called $spacing-scale with specific spacing values, then create a variable for the base spacing unit, generate a new map with doubled spacing values, and finally output CSS custom properties for these spacing values.
📋 What You'll Learn
Create a Sass map named $spacing-scale with keys small, medium, and large and values 0.5rem, 1rem, and 2rem respectively.
Create a variable named $base-spacing and set it to 1rem.
Generate a new Sass map named $double-spacing by multiplying each value in $spacing-scale by 2.
Output CSS custom properties for each key in $double-spacing inside the :root selector.
💡 Why This Matters
🌍 Real World
Spacing scales help keep website design consistent and easy to update by centralizing spacing values.
💼 Career
Front-end developers use Sass maps and loops to manage design tokens like spacing, colors, and fonts efficiently.
Progress0 / 4 steps
1
Create the initial spacing scale map
Create a Sass map called $spacing-scale with these exact entries: small: 0.5rem, medium: 1rem, and large: 2rem.
SASS
Need a hint?

Use parentheses ( ) to create a Sass map and separate key-value pairs with commas.

2
Add a base spacing variable
Create a variable called $base-spacing and set it to 1rem.
SASS
Need a hint?

Variables in Sass start with $. Assign the value with a colon and end with a semicolon.

3
Generate doubled spacing map
Create a new Sass map called $double-spacing by multiplying each value in $spacing-scale by 2 using a @each loop and map-merge().
SASS
Need a hint?

Use @each $key, $value in $spacing-scale to loop. Use map-merge() to add to a map.

4
Output CSS custom properties for doubled spacing
Write CSS inside the :root selector that outputs custom properties for each key in $double-spacing using a @each loop. The property names should be --spacing- followed by the key, and the values should be the doubled spacing values.
SASS
Need a hint?

Use :root selector and inside it use @each $key, $value in $double-spacing. Output custom properties with --spacing-#{$key}: #{$value};.