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
Why Custom Grids Offer Control
📖 Scenario: You are building a simple webpage layout using CSS Grid with Sass. You want to create a custom grid that gives you control over the number of columns and the gap between them. This helps you arrange content neatly and responsively.
🎯 Goal: Create a Sass variable for the number of columns, another for the gap size, then write a CSS Grid container style that uses these variables to control the grid layout.
📋 What You'll Learn
Create a Sass variable $columns with the value 4
Create a Sass variable $gap with the value 1.5rem
Write a CSS class .grid-container that uses display: grid;
Use grid-template-columns with repeat($columns, 1fr) to create equal columns
Use gap property with the $gap variable
💡 Why This Matters
🌍 Real World
Custom grids let web designers control layout easily and consistently across pages.
💼 Career
Knowing how to use Sass variables with CSS Grid is a valuable skill for front-end developers to build responsive, maintainable layouts.
Progress0 / 4 steps
1
Set up the number of columns variable
Create a Sass variable called $columns and set it to 4.
SASS
Hint
Use $columns: 4; to create the variable.
2
Add the gap size variable
Add a Sass variable called $gap and set it to 1.5rem.
SASS
Hint
Use $gap: 1.5rem; to create the gap variable.
3
Create the grid container class
Write a CSS class called .grid-container that sets display: grid;.
SASS
Hint
Use display: grid; inside the .grid-container class.
4
Use variables to define columns and gap
Inside the .grid-container class, add grid-template-columns: repeat($columns, 1fr); and gap: $gap; to control the grid layout.
SASS
Hint
Use grid-template-columns: repeat($columns, 1fr); and gap: $gap; inside the .grid-container class.
Practice
(1/5)
1. Why do custom grids in Sass give you more control over your webpage layout?
easy
A. Because you can define exact column sizes and spacing easily
B. Because they automatically fix all browser bugs
C. Because they remove the need for any CSS at all
D. Because they force all elements to be the same size
Solution
Step 1: Understand what custom grids do
Custom grids let you set specific column widths and gaps, unlike fixed grids.
Step 2: Recognize the benefit of control
This control helps you create layouts that fit your design needs exactly.
Final Answer:
Because you can define exact column sizes and spacing easily -> Option A
Quick Check:
Custom grids = precise layout control [OK]
Hint: Custom grids let you set sizes and gaps yourself [OK]
A. Missing comma between $cols and 1fr in repeat()
B. Using display: grid instead of flex
C. gap property should be gap: 1px
D. Mixin name cannot be 'grid'
Solution
Step 1: Check repeat() syntax
repeat() requires a comma between the count and size: repeat($cols, 1fr).
Step 2: Verify other properties
display: grid and gap: 1rem are correct and valid.
Final Answer:
Missing comma between $cols and 1fr in repeat() -> Option A
Quick Check:
repeat() needs comma between arguments [OK]
Hint: repeat() arguments must be comma-separated [OK]
Common Mistakes:
Omitting comma inside repeat()
Confusing grid with flex display
Changing gap units unnecessarily
5. You want a responsive custom grid in Sass that changes from 4 columns on large screens to 2 columns on small screens. Which approach gives you the best control?
hard
A. Write fixed CSS with 4 columns only and rely on browser zoom for small screens
B. Use a mixin with a parameter for columns and add media queries inside it to adjust columns based on screen width
C. Use a mixin that always sets 2 columns regardless of screen size
D. Avoid grids and use floats for layout instead
Solution
Step 1: Understand responsive design needs
Layouts must adapt to screen size, so columns should change with media queries.
Step 2: Use mixin with parameters and media queries
Mixins let you reuse code and media queries inside them adjust columns dynamically.
Final Answer:
Use a mixin with a parameter for columns and add media queries inside it to adjust columns based on screen width -> Option B
Quick Check:
Mixin + media queries = flexible responsive grid [OK]
Hint: Combine mixins with media queries for responsive grids [OK]