A container query lets you apply styles to an element based on the size of its container, not the whole viewport. It helps make components adapt to their space.
Click to reveal answer
beginner
How do you declare a container in CSS for container queries?
Use container-type property on the parent element. For example, container-type: inline-size; makes the container track its inline size (width in horizontal writing modes).
Click to reveal answer
intermediate
Why prepare your Sass code for container queries?
Preparing Sass helps organize styles, reuse code, and easily add container queries later without rewriting everything.
Click to reveal answer
intermediate
What Sass feature helps you write container queries cleanly?
Sass mixins let you write container query blocks once and reuse them with different parameters for cleaner code.
Click to reveal answer
beginner
How do container queries improve responsive design compared to media queries?
Container queries respond to the container's size, so components adapt wherever they are used, not just based on the whole screen size like media queries.
Click to reveal answer
Which CSS property defines a container for container queries?
Aquery-container
Bcontainer-query
Ccontainer-type
Dcontainer-style
✗ Incorrect
The correct property to declare a container is container-type.
What does container-type: inline-size; do?
ATracks the container's width for queries
BTracks the container's height for queries
CDisables container queries
DSets container background color
✗ Incorrect
inline-size tracks the container's inline size (width in horizontal writing modes), enabling queries based on width.
Why use Sass mixins for container queries?
ATo create animations
BTo disable container queries
CTo write JavaScript inside CSS
DTo reuse container query styles easily
✗ Incorrect
Mixins help reuse container query styles without repeating code.
Container queries respond to which size?
AContainer size
BViewport size
CFont size
DScreen resolution
✗ Incorrect
Container queries respond to the size of the container element.
Which is NOT a benefit of container queries?
AComponents adapt to container size
BStyles depend on viewport only
CBetter modular design
DMore flexible responsive layouts
✗ Incorrect
Container queries do NOT depend only on viewport size; that is media queries.
Explain how to prepare Sass code for container queries in a project.
Think about how Sass features help manage container queries.
You got /4 concepts.
Describe the difference between container queries and media queries.
Focus on what triggers the style changes.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using @container in Sass?
easy
A. To reset all container styles
B. To create animations for containers
C. To define variables inside containers
D. To apply styles based on the size of an element's container
Solution
Step 1: Understand container queries
Container queries allow styling elements depending on their container's size, not the viewport.
Step 2: Role of @container in Sass
The @container rule in Sass is used to write container queries clearly and apply styles conditionally based on container size.
Final Answer:
To apply styles based on the size of an element's container -> Option D
Quick Check:
Container queries = style by container size [OK]
Hint: Remember: @container styles depend on container size, not viewport [OK]
Common Mistakes:
Confusing container queries with media queries
Thinking @container creates animations
Using @container to define variables
2. Which CSS property must be set on a container element to enable container queries in Sass?
The condition inside @container must have a colon after the property name, e.g., max-width: 400px.
Step 2: Verify other options
The selector .card is valid, padding in rem is allowed, and max-width is a valid container query condition.
Final Answer:
Missing colon after max-width -> Option C
Quick Check:
Container query conditions need colons [OK]
Hint: Always use colon after property in container query conditions [OK]
Common Mistakes:
Omitting colon in container query conditions
Thinking max-width is invalid in container queries
Confusing units for padding
5. You want to style a .card component differently when its container is narrower than 300px or wider than 700px using Sass container queries. Which of the following is the correct way to write this?