Challenge - 5 Problems
SASS Mixin Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediateWhat is the output CSS of this SASS mixin usage?
Given the following SASS code, what CSS will be generated?
$color-primary: #3498db;
@mixin button-style($bg-color) {
background-color: $bg-color;
border: none;
padding: 1rem 2rem;
color: white;
cursor: pointer;
}
.button {
@include button-style($color-primary);
}SASS
$color-primary: #3498db; @mixin button-style($bg-color) { background-color: $bg-color; border: none; padding: 1rem 2rem; color: white; cursor: pointer; } .button { @include button-style($color-primary); }
Attempts:
2 left
💡 Hint
Remember that variables are replaced with their values when compiled.
✗ Incorrect
The mixin uses the variable $color-primary which is #3498db. The mixin sets background-color to that value, so the output CSS uses the hex color code, not the variable name.
🧠 Conceptual
intermediateWhich statement best describes the purpose of mixin libraries in SASS?
Choose the best explanation for why developers use mixin libraries in SASS.
Attempts:
2 left
💡 Hint
Think about how mixins help with writing CSS code.
✗ Incorrect
Mixin libraries group reusable styles that can accept parameters, so you write less code and keep styles consistent.
❓ selector
advancedWhat CSS selector is generated by this nested SASS mixin usage?
Given this SASS code, what is the full CSS selector for the nested styles?
@mixin card-style {
border: 1px solid #ccc;
padding: 1rem;
.title {
font-weight: bold;
}
}
.article {
@include card-style;
}SASS
@mixin card-style { border: 1px solid #ccc; padding: 1rem; .title { font-weight: bold; } } .article { @include card-style; }
Attempts:
2 left
💡 Hint
Nested selectors inside mixins become nested in the output CSS relative to where the mixin is included.
✗ Incorrect
The nested .title inside the mixin becomes .article .title in CSS because the mixin is included inside .article block.
❓ layout
advancedHow does this SASS mixin help with responsive layout?
Examine this mixin and its usage. What is the main layout benefit it provides?
@mixin flex-center {
display: flex;
justify-content: center;
align-items: center;
}
.container {
@include flex-center;
height: 100vh;
}SASS
@mixin flex-center { display: flex; justify-content: center; align-items: center; } .container { @include flex-center; height: 100vh; }
Attempts:
2 left
💡 Hint
Think about what flexbox properties do for alignment.
✗ Incorrect
The mixin sets flexbox with center alignment on both axes, so content inside .container is perfectly centered regardless of screen size.
❓ accessibility
expertWhich mixin usage improves accessibility by enhancing focus styles?
Consider these four SASS mixin usages for focus styles. Which one best improves keyboard accessibility by making focus visible and clear?
@mixin focus-style-a {
outline: none;
}
@mixin focus-style-b {
outline: 2px solid blue;
outline-offset: 2px;
}
@mixin focus-style-c {
border: 1px solid transparent;
}
@mixin focus-style-d {
box-shadow: 0 0 0 3px rgba(21, 156, 228, 0.4);
}SASS
@mixin focus-style-a { outline: none; } @mixin focus-style-b { outline: 2px solid blue; outline-offset: 2px; } @mixin focus-style-c { border: 1px solid transparent; } @mixin focus-style-d { box-shadow: 0 0 0 3px rgba(21, 156, 228, 0.4); }
Attempts:
2 left
💡 Hint
Good focus styles must be visible and distinct for keyboard users.
✗ Incorrect
Removing outlines (A) harms accessibility. Transparent borders (C) do not show focus. Box-shadow (D) can be subtle but may not be as clear as a solid outline. Outline with offset (B) is a recommended accessible focus style.
