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
Grid system mixin from scratch
📖 Scenario: You are building a simple grid system for a website layout. This grid system will help arrange content in columns that adapt to different screen sizes. You will create a Sass mixin that generates CSS grid columns based on the number of columns you want.
🎯 Goal: Create a Sass mixin called grid-column that takes a number of columns as input and sets the width of the element accordingly. Use this mixin to style grid items so they fit nicely in a 12-column grid layout.
📋 What You'll Learn
Create a Sass variable for the total number of columns in the grid (12).
Write a mixin named grid-column that accepts a parameter $cols for the number of columns to span.
The mixin should calculate the width as a percentage based on $cols and the total columns.
Use the mixin to style grid items with different column spans.
Ensure the grid container uses CSS Flexbox to arrange items in a row.
💡 Why This Matters
🌍 Real World
Grid systems are used in web design to create clean, organized layouts that adapt to different screen sizes. This project shows how to build a simple grid system from scratch using Sass.
💼 Career
Understanding how to create and use mixins for layout helps front-end developers write reusable, maintainable CSS and build responsive websites efficiently.
Progress0 / 4 steps
1
Set up the total columns variable
Create a Sass variable called $total-columns and set it to 12 to represent the total number of columns in the grid.
SASS
Hint
Use $total-columns: 12; to define the total columns.
2
Create the grid-column mixin
Write a Sass mixin named grid-column that takes a parameter $cols. Inside the mixin, calculate the width as ($cols / $total-columns) * 100% and set it as the element's width.
D. Missing comma between $cols and 1fr in repeat() function
Solution
Step 1: Check syntax of repeat() function
The repeat() function requires a comma between the number and the size, like repeat($cols, 1fr).
Step 2: Verify other properties
Display is correctly set to grid, and gap is valid for grid layouts.
Final Answer:
Missing comma between $cols and 1fr in repeat() function -> Option D
Quick Check:
repeat() needs comma [OK]
Hint: Always put a comma inside repeat() between count and size [OK]
Common Mistakes:
Omitting comma in repeat()
Confusing display:flex with grid
Thinking gap is invalid in grid
5. You want a responsive grid mixin that changes columns based on screen width. Which Sass code correctly adds a media query inside the mixin to set 2 columns on screens smaller than 600px and 4 columns otherwise?