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
Container and Wrapper Patterns with Sass
📖 Scenario: You are building a simple webpage layout that uses container and wrapper patterns to center content and limit its width for better readability on large screens.
🎯 Goal: Create a Sass stylesheet that defines a .container class to center content with a max width and padding, and a .wrapper class that adds a background color and some spacing around the container.
📋 What You'll Learn
Create a .container class with a max-width of 60rem, horizontal auto margin, and 1.5rem padding on left and right.
Create a $wrapper-bg-color variable set to #f0f0f0.
Create a .wrapper class that uses the $wrapper-bg-color as background color and adds 2rem padding.
Nest the .container class inside the .wrapper class using Sass nesting.
💡 Why This Matters
🌍 Real World
Container and wrapper patterns are common in web design to keep content readable and visually appealing on different screen sizes.
💼 Career
Understanding these patterns and Sass nesting is important for front-end developers to write maintainable and scalable CSS.
Progress0 / 4 steps
1
Create the .container class
Write a Sass class called .container that sets max-width to 60rem, horizontal margins to auto, and horizontal padding to 1.5rem.
SASS
Hint
Use max-width to limit width, margin-left and margin-right set to auto to center horizontally, and padding-left and padding-right for horizontal spacing.
2
Add the $wrapper-bg-color variable
Create a Sass variable called $wrapper-bg-color and set it to the color #f0f0f0.
SASS
Hint
Use $wrapper-bg-color: #f0f0f0; to create the variable.
3
Create the .wrapper class with background and padding
Write a Sass class called .wrapper that sets background-color to $wrapper-bg-color and adds 2rem padding on all sides.
SASS
Hint
Use background-color: $wrapper-bg-color; and padding: 2rem; inside the .wrapper class.
4
Nest the .container class inside .wrapper
Nest the existing .container class inside the .wrapper class using Sass nesting syntax.
SASS
Hint
Move the .container class inside .wrapper using Sass nesting by placing .container { ... } inside .wrapper { ... }.
Practice
(1/5)
1. What is the main purpose of a container in Sass when building layouts?
easy
A. To add background colors to all page elements
B. To create animations for buttons
C. To center content and limit its maximum width for better readability
D. To change font sizes globally
Solution
Step 1: Understand container role in layout
A container is used to keep content centered and restrict its width so it doesn't stretch too wide on large screens.
Step 2: Compare options to container purpose
Options B, C, and D describe unrelated tasks like colors, animations, and fonts, which are not the container's main job.
Final Answer:
To center content and limit its maximum width for better readability -> Option C
Quick Check:
Container = center + max-width [OK]
Hint: Containers control width and center content [OK]
Common Mistakes:
Thinking containers add colors or animations
Confusing containers with global font settings
Ignoring the width limit role
2. Which of the following Sass code snippets correctly defines a reusable container mixin with max-width and horizontal centering?
easy
A. @mixin container { max-width: 1200px; margin: 10px; }
D. Mixin name 'container' is reserved and cannot be used
Solution
Step 1: Check syntax of each property
The line 'max-width 1200px;' is missing a colon ':' after 'max-width'. It should be 'max-width: 1200px;'.
Step 2: Verify other properties and naming
Margin shorthand and padding with rem are valid. The mixin name 'container' is allowed.
Final Answer:
Missing colon after 'max-width' property name -> Option B
Quick Check:
CSS properties need colon after name [OK]
Hint: CSS properties always need colon after name [OK]
Common Mistakes:
Forgetting colon after property name
Thinking rem units are invalid
Believing mixin names are reserved words
5. You want to create a responsive wrapper mixin in Sass that uses a max-width of 1200px on large screens, but 90% width on smaller screens, with horizontal centering and 2rem padding. Which code correctly implements this using container and media query?