Challenge - 5 Problems
Media Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output CSS of this SASS mixin usage?
Given the following SASS code, what CSS will be generated?
@mixin respond-to($breakpoint) {
@if $breakpoint == small {
@media (max-width: 600px) {
@content;
}
}
}
.box {
width: 100%;
@include respond-to(small) {
width: 50%;
}
}SASS
@mixin respond-to($breakpoint) { @if $breakpoint == small { @media (max-width: 600px) { @content; } } } .box { width: 100%; @include respond-to(small) { width: 50%; } }
Attempts:
2 left
💡 Hint
Look at how the mixin wraps the content inside a media query only for the 'small' breakpoint.
✗ Incorrect
The mixin checks if the breakpoint is 'small' and wraps the included styles inside a media query for max-width 600px. The base .box width is 100%, and inside the media query it changes to 50%.
🧠 Conceptual
intermediate1:30remaining
Which option correctly explains the benefit of using media query mixins?
Why do developers use media query mixins in SASS instead of writing media queries directly in CSS?
Attempts:
2 left
💡 Hint
Think about how mixins help avoid repeating the same code.
✗ Incorrect
Media query mixins let you write the media query condition once and reuse it multiple times, making your code cleaner and easier to maintain.
❓ selector
advanced2:00remaining
What CSS selector is generated by this nested media query mixin usage?
Consider this SASS code:
What is the CSS selector for the color red style?
@mixin respond-to($breakpoint) {
@if $breakpoint == medium {
@media (min-width: 601px) and (max-width: 900px) {
@content;
}
}
}
.container {
background: white;
.item {
color: black;
@include respond-to(medium) {
color: red;
}
}
}What is the CSS selector for the color red style?
SASS
@mixin respond-to($breakpoint) { @if $breakpoint == medium { @media (min-width: 601px) and (max-width: 900px) { @content; } } } .container { background: white; .item { color: black; @include respond-to(medium) { color: red; } } }
Attempts:
2 left
💡 Hint
Remember how nested selectors and media queries compile in SASS.
✗ Incorrect
The nested .item inside .container becomes .container .item in CSS. The media query wraps the entire selector with the styles inside it.
❓ layout
advanced2:00remaining
Which media query mixin usage correctly changes layout on large screens?
Given this mixin:
Which SASS snippet will make a grid container have 4 columns only on large screens?
@mixin respond-to($breakpoint) {
@if $breakpoint == large {
@media (min-width: 901px) {
@content;
}
}
}Which SASS snippet will make a grid container have 4 columns only on large screens?
SASS
@mixin respond-to($breakpoint) { @if $breakpoint == large { @media (min-width: 901px) { @content; } } }
Attempts:
2 left
💡 Hint
The base style applies to all screens, the mixin overrides it only on large screens.
✗ Incorrect
Option B sets 2 columns by default and changes to 4 columns inside the large screen media query. Others either override incorrectly or do not apply the media query properly.
❓ accessibility
expert2:30remaining
How can media query mixins improve accessibility for users with reduced motion preferences?
Consider this SASS mixin:
Which usage best respects users who want less motion animations?
@mixin prefers-reduced-motion {
@media (prefers-reduced-motion: reduce) {
@content;
}
}Which usage best respects users who want less motion animations?
SASS
@mixin prefers-reduced-motion { @media (prefers-reduced-motion: reduce) { @content; } }
Attempts:
2 left
💡 Hint
Think about how to disable animations for users who prefer reduced motion.
✗ Incorrect
Option A disables the animation inside the prefers-reduced-motion media query, respecting user preferences. Others either do not disable or incorrectly apply styles.