0
0
SASSmarkup~20 mins

Mixin definition with @mixin in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SASS Mixin 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 code using a mixin?
Given the following SASS code, what CSS will be generated in the browser?
SASS
@mixin center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.box {
  @include center;
  width: 100px;
  height: 100px;
  background-color: red;
}
A
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.box {
  width: 100px;
  height: 100px;
  background-color: red;
}
B
.box {
  width: 100px;
  height: 100px;
  background-color: red;
}
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}
C
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100px;
  height: 100px;
  background-color: red;
}
D
.box {
  display: block;
  width: 100px;
  height: 100px;
  background-color: red;
}
Attempts:
2 left
💡 Hint
Remember that @include inserts the mixin's styles inside the selector.
🧠 Conceptual
intermediate
1:30remaining
What does the @mixin directive do in SASS?
Choose the best description of what @mixin does in SASS.
ACreates a new CSS class automatically.
BDefines reusable blocks of styles that can be included in selectors.
CImports external CSS files into the current stylesheet.
DDefines variables that store color values.
Attempts:
2 left
💡 Hint
Think about how you avoid repeating the same styles in multiple places.
selector
advanced
2:00remaining
Which option correctly uses a mixin with parameters?
Given this mixin definition, which usage will produce a blue border of 2px thickness? @mixin border($color, $width) { border: $width solid $color; }
SASS
@mixin border($color, $width) {
  border: $width solid $color;
}
A
.box {
  @include border(blue, 2px);
}
B
.box {
  @include border(2px, blue);
}
C
.box {
  @include border(blue);
}
D
.box {
  @include border($color: blue);
}
Attempts:
2 left
💡 Hint
Parameters are passed in the order they are defined unless named.
layout
advanced
2:30remaining
What visual layout will this SASS code produce?
Consider this SASS code using a mixin for grid layout: @mixin grid-layout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; } .container { @include grid-layout; background-color: lightgray; padding: 1rem; } What will the .container look like in the browser?
SASS
@mixin grid-layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.container {
  @include grid-layout;
  background-color: lightgray;
  padding: 1rem;
}
AA container with grid layout but no gaps and no background color.
BA container with a single column and no gaps, white background, and no padding.
CA container with flex layout and items centered horizontally and vertically.
DA container with three equal columns spaced evenly with gaps, light gray background, and padding.
Attempts:
2 left
💡 Hint
The mixin sets a grid with 3 equal columns and gaps.
accessibility
expert
3:00remaining
How can a mixin help improve accessibility in CSS?
Which of these mixin usages best helps maintain accessible focus styles across a website?
A
@mixin focus-style {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}

.button {
  @include focus-style;
}
B
@mixin focus-style {
  display: none;
}

.button {
  @include focus-style;
}
C
@mixin focus-style {
  color: transparent;
}

.button {
  @include focus-style;
}
D
@mixin focus-style {
  background-color: white;
}

.button {
  @include focus-style;
}
Attempts:
2 left
💡 Hint
Accessible focus styles help keyboard users see which element is focused.