Challenge - 5 Problems
Sass Nesting 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 nested Sass code?
Given the following Sass code, what is the compiled CSS output?
SASS
$primary-color: #3498db; .button { color: $primary-color; &:hover { color: darken($primary-color, 10%); } &.active { color: lighten($primary-color, 20%); } }
Attempts:
2 left
💡 Hint
Look at how & is used to create related selectors and how color functions adjust the base color.
✗ Incorrect
The & symbol in Sass refers to the parent selector. &:hover compiles to .button:hover and &.active compiles to .button.active. The darken and lighten functions adjust the base color accordingly.
❓ rendering
intermediate1:30remaining
How many CSS rules are generated from this Sass nesting?
Consider this Sass code snippet. How many distinct CSS rules will be generated after compilation?
.card {
border: 1px solid #ccc;
.title {
font-weight: bold;
}
&:hover {
border-color: #999;
}
}
SASS
.card { border: 1px solid #ccc; .title { font-weight: bold; } &:hover { border-color: #999; } }
Attempts:
2 left
💡 Hint
Count each unique selector generated by nesting and & usage.
✗ Incorrect
The code generates three CSS rules: one for .card, one for .card .title, and one for .card:hover. So total 3 rules.
❓ selector
advanced2:00remaining
Which option correctly nests pseudo-elements with property nesting?
You want to style a button's ::before pseudo-element inside the button class using Sass nesting. Which option produces the correct CSS?
SASS
.button { color: blue; /* pseudo-element styling here */ }
Attempts:
2 left
💡 Hint
Use & with the correct pseudo-element syntax.
✗ Incorrect
In Sass, to nest pseudo-elements, you use & followed by the pseudo-element with double colons (::before). Option A correctly nests it. Option A uses single colon which is deprecated for pseudo-elements.
❓ accessibility
advanced2:00remaining
How to nest focus styles accessibly using Sass?
You want to add a visible focus outline to links inside a navigation bar using Sass nesting. Which option correctly applies an accessible focus style?
SASS
nav {
a {
color: black;
/* focus style here */
}
}Attempts:
2 left
💡 Hint
Use the pseudo-class that shows focus only when keyboard navigation is used.
✗ Incorrect
The :focus-visible pseudo-class applies styles only when focus is visible (usually keyboard focus), improving accessibility by not showing outlines on mouse clicks. Option B uses &:focus-visible correctly nested.
❓ layout
expert2:30remaining
What is the final computed margin for .container > .item when using this nested Sass?
Given this Sass code, what is the margin applied to .container > .item in the compiled CSS?
.container {
padding: 1rem;
> .item {
margin: 0.5rem;
&.highlight {
margin: 1rem;
}
}
}
SASS
.container { padding: 1rem; > .item { margin: 0.5rem; &.highlight { margin: 1rem; } } }
Attempts:
2 left
💡 Hint
The base margin applies to all .item children; the .highlight class overrides margin only when present.
✗ Incorrect
The selector > .item applies margin: 0.5rem to all direct .item children of .container. The nested &.highlight applies margin: 1rem only if the .item also has the highlight class. So for a normal .item, margin is 0.5rem.