Challenge - 5 Problems
Sass Content Block Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output CSS of this Sass code using @content?
Consider the following Sass code. What CSS does it produce when compiled?
@mixin card() {
border: 1px solid #ccc;
padding: 1rem;
@content;
background: white;
}
.container {
@include card() {
box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
}SASS
@mixin card() { border: 1px solid #ccc; padding: 1rem; @content; background: white; } .container { @include card() { box-shadow: 0 0 5px rgba(0,0,0,0.1); } }
Attempts:
2 left
💡 Hint
Remember that @content inserts the block exactly where it is placed inside the mixin.
✗ Incorrect
The @content block is inserted exactly where @content is called inside the mixin. So the box-shadow property appears between padding and background inside the .container rule.
🧠 Conceptual
intermediate2:00remaining
What happens if @content is missing inside a mixin?
Given this Sass mixin:
What will happen if you include it without providing a content block like this?
@mixin highlight() {
background-color: yellow;
@content;
border: 1px solid orange;
}What will happen if you include it without providing a content block like this?
.note {
@include highlight();
}SASS
@mixin highlight() { background-color: yellow; @content; border: 1px solid orange; } .note { @include highlight(); }
Attempts:
2 left
💡 Hint
Think about what @content does when no block is passed.
✗ Incorrect
If no content block is passed, @content is simply ignored and the rest of the mixin styles apply normally.
❓ selector
advanced2:00remaining
How does @content affect nested selectors inside a mixin?
Look at this Sass code:
What CSS will be generated for the .btn:hover selector?
@mixin button-style() {
padding: 0.5rem 1rem;
border-radius: 0.25rem;
@content;
&:hover {
background-color: #eee;
}
}
.btn {
@include button-style() {
background-color: blue;
color: white;
}
}What CSS will be generated for the .btn:hover selector?
SASS
@mixin button-style() { padding: 0.5rem 1rem; border-radius: 0.25rem; @content; &:hover { background-color: #eee; } } .btn { @include button-style() { background-color: blue; color: white; } }
Attempts:
2 left
💡 Hint
Remember that @content inserts styles inside the main selector, but &:hover is a nested selector inside the mixin.
✗ Incorrect
The &:hover block inside the mixin creates a .btn:hover selector with background-color #eee. The @content block inserts styles inside .btn, not inside :hover.
❓ rendering
advanced2:00remaining
What visual effect will this Sass code produce?
Given this Sass code:
What will the .article box look like in a browser?
@mixin card() {
border: 2px solid black;
padding: 1rem;
background: white;
@content;
}
.article {
@include card() {
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
border-radius: 0.5rem;
}
}What will the .article box look like in a browser?
SASS
@mixin card() { border: 2px solid black; padding: 1rem; background: white; @content; } .article { @include card() { box-shadow: 0 4px 6px rgba(0,0,0,0.1); border-radius: 0.5rem; } }
Attempts:
2 left
💡 Hint
The @content block adds extra styles inside the box.
✗ Incorrect
The mixin sets border, padding, and background. The @content block adds box-shadow and border-radius inside the same selector, so all styles combine visually.
❓ accessibility
expert3:00remaining
How can @content help improve accessibility in Sass components?
You want to create a reusable button style mixin that allows adding accessible focus styles via @content. Which approach below correctly uses @content to insert focus styles while keeping the base styles consistent?
How should you include this mixin to add a visible focus outline for keyboard users?
@mixin accessible-button() {
padding: 0.75rem 1.5rem;
border: none;
background-color: #007BFF;
color: white;
cursor: pointer;
@content;
}How should you include this mixin to add a visible focus outline for keyboard users?
SASS
@mixin accessible-button() { padding: 0.75rem 1.5rem; border: none; background-color: #007BFF; color: white; cursor: pointer; @content; } .button { @include accessible-button() { &:focus-visible { outline: 3px solid #FFD700; outline-offset: 2px; } } }
Attempts:
2 left
💡 Hint
Think about how @content lets you add custom nested selectors inside a reusable style block.
✗ Incorrect
Using @content inside the mixin allows you to add custom nested selectors like &:focus-visible when including the mixin, keeping all related styles together and improving maintainability and accessibility.