0
0
SASSmarkup~20 mins

Media query mixin patterns in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Media Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2: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%;
  }
}
A
.box {
  width: 100%;
}

@media (max-width: 600px) {
  .box {
    width: 50%;
  }
}
B
.box {
  width: 100%;
  width: 50%;
}
C
.box {
  width: 50%;
}

@media (max-width: 600px) {
  .box {
    width: 100%;
  }
}
D
@media (max-width: 600px) {
  .box {
    width: 100%;
  }
}
Attempts:
2 left
💡 Hint
Look at how the mixin wraps the content inside a media query only for the 'small' breakpoint.
🧠 Conceptual
intermediate
1: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?
AThey replace the need for CSS variables in responsive design.
BThey automatically optimize media queries for all browsers without extra code.
CThey convert media queries into JavaScript for dynamic resizing.
DThey allow reusing media query logic and keep code DRY (Don't Repeat Yourself).
Attempts:
2 left
💡 Hint
Think about how mixins help avoid repeating the same code.
selector
advanced
2:00remaining
What CSS selector is generated by this nested media query mixin usage?
Consider this SASS code:
@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;
    }
  }
}
A
.item {
  color: red;
}
B
.container {
  .item {
    @media (min-width: 601px) and (max-width: 900px) {
      color: red;
    }
  }
}
C
@media (min-width: 601px) and (max-width: 900px) {
  .container .item {
    color: red;
  }
}
D
.container .item {
  color: red;
  @media (min-width: 601px) and (max-width: 900px) {
  }
}
Attempts:
2 left
💡 Hint
Remember how nested selectors and media queries compile in SASS.
layout
advanced
2:00remaining
Which media query mixin usage correctly changes layout on large screens?
Given this mixin:
@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;
    }
  }
}
A
.grid {
  display: grid;
  @include respond-to(large) {
    grid-template-columns: repeat(4, 1fr);
  }
  grid-template-columns: repeat(2, 1fr);
}
B
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  @include respond-to(large) {
    grid-template-columns: repeat(4, 1fr);
  }
}
C
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  @include respond-to(large) {
    grid-template-columns: repeat(2, 1fr);
  }
}
D
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-columns: repeat(4, 1fr);
}
Attempts:
2 left
💡 Hint
The base style applies to all screens, the mixin overrides it only on large screens.
accessibility
expert
2:30remaining
How can media query mixins improve accessibility for users with reduced motion preferences?
Consider this SASS mixin:
@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;
  }
}
A
.animation {
  animation: spin 2s linear infinite;
  @include prefers-reduced-motion {
    animation: none;
  }
}
B
.animation {
  animation: spin 2s linear infinite;
  @include prefers-reduced-motion {
    animation: spin 1s linear infinite;
  }
}
C
.animation {
  animation: spin 2s linear infinite;
  @media (prefers-reduced-motion: no-preference) {
    animation: none;
  }
}
D
.animation {
  animation: spin 2s linear infinite;
  animation-play-state: paused;
}
Attempts:
2 left
💡 Hint
Think about how to disable animations for users who prefer reduced motion.