0
0
SASSmarkup~20 mins

Responsive breakpoint mixin patterns in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Responsive Breakpoint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding breakpoint mixin usage
Given this Sass mixin for a responsive breakpoint:
@mixin respond-to($breakpoint) {
  @if $breakpoint == small {
    @media (max-width: 600px) { @content; }
  } @else if $breakpoint == medium {
    @media (min-width: 601px) and (max-width: 1024px) { @content; }
  } @else if $breakpoint == large {
    @media (min-width: 1025px) { @content; }
  }
}

What CSS will be generated by this Sass code?
.box {
  width: 100%;
  @include respond-to(medium) {
    width: 50%;
  }
}
SASS
@mixin respond-to($breakpoint) {
  @if $breakpoint == small {
    @media (max-width: 600px) { @content; }
  } @else if $breakpoint == medium {
    @media (min-width: 601px) and (max-width: 1024px) { @content; }
  } @else if $breakpoint == large {
    @media (min-width: 1025px) { @content; }
  }
}

.box {
  width: 100%;
  @include respond-to(medium) {
    width: 50%;
  }
}
A
.box {
  width: 100%;
}
@media (min-width: 601px) and (max-width: 1024px) {
  .box {
    width: 50%;
  }
}
B
.box {
  width: 100%;
  width: 50%;
}
C
@media (max-width: 600px) {
  .box {
    width: 50%;
  }
}
D
.box {
  width: 50%;
}
Attempts:
2 left
💡 Hint
Look at which media query matches the 'medium' breakpoint in the mixin.
📝 Syntax
intermediate
2:00remaining
Fix the syntax error in this breakpoint mixin call
Which option correctly fixes the syntax error in this Sass code?
@mixin breakpoint($size) {
  @if $size == mobile {
    @media (max-width: 480px) { @content; }
  } @else if $size == tablet {
    @media (min-width: 481px) and (max-width: 768px) { @content; }
  }
}

.container {
  @include breakpoint mobile {
    padding: 1rem;
  }
}
SASS
@mixin breakpoint($size) {
  @if $size == mobile {
    @media (max-width: 480px) { @content; }
  } @else if $size == tablet {
    @media (min-width: 481px) and (max-width: 768px) { @content; }
  }
}

.container {
  @include breakpoint mobile {
    padding: 1rem;
  }
}
A
@include breakpoint('mobile') {
  padding: 1rem;
}
B
@include breakpoint($mobile) {
  padding: 1rem;
}
C
@include breakpoint mobile {
  padding: 1rem;
}
D
@include breakpoint(mobile) {
  padding: 1rem;
}
Attempts:
2 left
💡 Hint
Mixin arguments must be enclosed in parentheses without quotes if they are identifiers.
selector
advanced
2:00remaining
Which selector is targeted inside this breakpoint mixin?
Consider this Sass code:
@mixin respond($bp) {
  @if $bp == desktop {
    @media (min-width: 1024px) { @content; }
  }
}

nav {
  color: black;
  @include respond(desktop) {
    color: blue;
  }
}

What CSS selector will have the color blue inside the media query?
SASS
@mixin respond($bp) {
  @if $bp == desktop {
    @media (min-width: 1024px) { @content; }
  }
}

nav {
  color: black;
  @include respond(desktop) {
    color: blue;
  }
}
Anav
B.nav
C*
D#nav
Attempts:
2 left
💡 Hint
Look at the selector used before the mixin call.
layout
advanced
2:00remaining
What layout change happens at this breakpoint?
Given this Sass code:
@mixin breakpoint($size) {
  @if $size == mobile {
    @media (max-width: 600px) { @content; }
  }
}

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  @include breakpoint(mobile) {
    grid-template-columns: 1fr;
  }
}

What will the grid layout look like on a screen 500px wide?
SASS
@mixin breakpoint($size) {
  @if $size == mobile {
    @media (max-width: 600px) { @content; }
  }
}

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  @include breakpoint(mobile) {
    grid-template-columns: 1fr;
  }
}
AA four column grid with equal width columns
BA single column grid with all items stacked vertically
CA two column grid with uneven column widths
DNo grid layout applied
Attempts:
2 left
💡 Hint
Check the media query for max-width 600px and the grid-template-columns inside it.
accessibility
expert
2:00remaining
Accessibility impact of breakpoint mixin usage
You use a breakpoint mixin to hide a navigation menu on small screens:
@mixin hide-on-small {
  @media (max-width: 600px) {
    display: none;
  }
}

nav {
  @include hide-on-small;
}

What is a potential accessibility issue with this approach?
SASS
@mixin hide-on-small {
  @media (max-width: 600px) {
    display: none;
  }
}

nav {
  @include hide-on-small;
}
AThe nav remains visible on all screen sizes, so no issue
BThe nav is completely removed from the DOM, so keyboard users lose access
CUsing display:none hides content visually and from assistive tech, possibly removing keyboard access
DScreen readers may still read the hidden nav, causing confusion
Attempts:
2 left
💡 Hint
Consider how display:none affects both visual and assistive technologies.