0
0
SASSmarkup~20 mins

Content blocks with @content in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Content Block 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 @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);
  }
}
A
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  background: white;
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
B
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  background: white;
}
.container {
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
C
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
  background: white;
}
D
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  background: white;
}
.box-shadow {
  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.
🧠 Conceptual
intermediate
2:00remaining
What happens if @content is missing inside a mixin?
Given this Sass mixin:
@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();
}
AThe .note class will have yellow background and orange border, but no extra styles inside.
BIt will cause a syntax error because @content is required.
CThe mixin will be ignored and .note will have no styles.
DThe .note class will be empty because @content is missing.
Attempts:
2 left
💡 Hint
Think about what @content does when no block is passed.
selector
advanced
2:00remaining
How does @content affect nested selectors inside a mixin?
Look at this Sass code:
@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;
  }
}
A
.btn:hover {
  background-color: blue;
  color: white;
}
B
.btn:hover {
  background-color: #eee;
}
C
.btn:hover {
  background-color: #eee;
  background-color: blue;
  color: white;
}
DNo .btn:hover selector is generated.
Attempts:
2 left
💡 Hint
Remember that @content inserts styles inside the main selector, but &:hover is a nested selector inside the mixin.
rendering
advanced
2:00remaining
What visual effect will this Sass code produce?
Given this Sass code:
@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;
  }
}
AA white box with a black border, some padding, a subtle shadow, and rounded corners.
BA white box with a black border and padding but no shadow or rounded corners.
CA box with only shadow and rounded corners but no border or padding.
DA transparent box with no visible border, shadow, or padding.
Attempts:
2 left
💡 Hint
The @content block adds extra styles inside the box.
accessibility
expert
3: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?
@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;
    }
  }
}
AAdd focus styles outside the mixin, separately targeting .button:focus-visible.
BUse JavaScript to add focus styles instead of Sass @content.
CAdd focus styles inside the mixin before @content without using a content block.
DInclude the mixin with a content block that adds &:focus-visible styles inside the button selector.
Attempts:
2 left
💡 Hint
Think about how @content lets you add custom nested selectors inside a reusable style block.