Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Offset Class Generation with Sass
📖 Scenario: You are building a responsive grid system for a website. To help with layout spacing, you want to create offset classes that move columns to the right by a certain number of grid spaces.
🎯 Goal: Create Sass code that generates CSS offset classes named .offset-1 through .offset-12. Each class should apply a margin-left equal to the number of grid spaces multiplied by a base column width of 8.3333% (which is 100% divided by 12 columns).
📋 What You'll Learn
Create a Sass list of numbers from 1 to 12 representing offset steps.
Create a variable for the base column width set to 8.3333%.
Use a Sass @each loop to generate offset classes from .offset-1 to .offset-12.
Each offset class should set margin-left to the offset number multiplied by the base column width.
💡 Why This Matters
🌍 Real World
Grid systems are common in web design to create flexible layouts. Offset classes help position content with consistent spacing.
💼 Career
Knowing how to generate CSS classes with Sass loops saves time and reduces errors in professional front-end development.
Progress0 / 4 steps
1
Create the offset steps list
Create a Sass list variable called $offset-steps with the numbers from 1 to 12 separated by spaces.
SASS
Hint
Use parentheses or just spaces to create a list in Sass, like $list: 1 2 3;.
2
Define the base column width variable
Create a Sass variable called $base-column-width and set it to 8.3333%.
SASS
Hint
Set the variable with a colon and end with a semicolon, like $var: value;.
3
Generate offset classes with a loop
Use a Sass @each loop with the variable $i to iterate over $offset-steps. Inside the loop, create a class named .offset-#{$i} that sets margin-left to $i multiplied by $base-column-width.
SASS
Hint
Use @each $i in $offset-steps { ... } and inside create .offset-#{$i} with margin-left: $i * $base-column-width;.
4
Add a comment describing the offset classes
Add a Sass comment at the top of the file that says // Offset classes for grid spacing.
SASS
Hint
Use // to add a single-line comment in Sass.
Practice
(1/5)
1. What is the main purpose of offset classes in Sass-generated CSS?
easy
A. To hide elements from the page
B. To change the background color of elements
C. To reduce the font size of text
D. To move elements to the right by adding left margin
Solution
Step 1: Understand offset class function
Offset classes add left margin to elements, shifting them right.
Step 2: Compare options with offset purpose
Only To move elements to the right by adding left margin describes moving elements right by left margin.
Final Answer:
To move elements to the right by adding left margin -> Option D
Quick Check:
Offset classes = move right by left margin [OK]
Hint: Offsets add left margin to shift elements right [OK]
Common Mistakes:
Confusing offset with color or font changes
Thinking offset hides elements
Assuming offset changes element width
2. Which Sass syntax correctly generates offset classes from 1 to 4 with 1rem increments?