Recall & Review
beginner
What is a mixin in Sass?
A mixin is a reusable block of styles that you can include in other selectors to avoid repeating code.
Click to reveal answer
beginner
How does the @if directive work inside a Sass mixin?
The @if directive lets you add conditions inside a mixin to apply styles only when certain rules are true.
Click to reveal answer
intermediate
Example: What will this Sass code do?
@mixin color-theme($theme) {
@if $theme == light {
background: white;
color: black;
} @else if $theme == dark {
background: black;
color: white;
}
}
.button {
@include color-theme(dark);
}
It will create a .button class with a black background and white text because the mixin applies styles for the 'dark' theme.Click to reveal answer
intermediate
Why use conditional mixins instead of writing separate classes?
Conditional mixins keep your code DRY (Don't Repeat Yourself) by reusing style blocks with small changes based on conditions.
Click to reveal answer
beginner
Can you use multiple @if, @else if, and @else inside one mixin?
Yes, you can chain multiple conditions to handle different cases inside a single mixin.
Click to reveal answer
What does the @if directive do inside a Sass mixin?
✗ Incorrect
The @if directive checks a condition and applies styles only when that condition is true.
How do you include a mixin named 'button-style' in Sass?
✗ Incorrect
You use @include followed by the mixin name to add its styles.
Which of these is a valid condition in a Sass @if statement?
✗ Incorrect
You compare variables with == and strings can be unquoted if they are color names or identifiers.
What happens if none of the @if or @else if conditions match and there is an @else block?
✗ Incorrect
The @else block runs when no previous conditions are true.
Why are conditional mixins helpful in Sass?
✗ Incorrect
Conditional mixins let you change styles based on variables, making your CSS flexible.
Explain how you would use a conditional mixin in Sass to change button colors based on a theme variable.
Think about checking the theme variable inside the mixin and applying different colors.
You got /5 concepts.
Describe the benefits of using @if inside mixins compared to writing separate CSS classes for each style variation.
Consider how conditional mixins keep your code clean and flexible.
You got /4 concepts.