Challenge - 5 Problems
Sass Nesting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2:00remaining
What CSS does this Sass code produce?
Given the Sass code below, what is the resulting CSS output?
SASS
nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li {
display: inline-block;
}
a {
text-decoration: none;
}
}Attempts:
2 left
💡 Hint
Remember that nested selectors in Sass combine the parent selector with the nested one.
✗ Incorrect
In Sass, nesting selectors inside another selector combines them by placing the parent selector before the nested one, separated by a space. So 'nav { ul { ... } }' becomes 'nav ul { ... }' in CSS.
❓ selector
intermediate2:00remaining
Which option shows the correct nested Sass for this CSS?
Given this CSS, which Sass code would produce it?
nav ul {
margin: 0;
}
nav ul li {
display: block;
}
nav ul li a {
color: blue;
}
Attempts:
2 left
💡 Hint
Think about how nesting inside 'ul' inside 'nav' matches the CSS selectors.
✗ Incorrect
Nesting 'li' inside 'ul' inside 'nav' in Sass creates selectors like 'nav ul li' in CSS. Further nesting 'a' inside 'li' inside 'ul' inside 'nav' creates 'nav ul li a'.
❓ selector
advanced2:00remaining
What is the output CSS of this Sass with parent selector &?
Consider this Sass code:
.button {
color: white;
&-primary {
background: blue;
}
&-secondary {
background: gray;
}
}
Attempts:
2 left
💡 Hint
The & symbol in Sass means 'use the parent selector here'.
✗ Incorrect
Using &-primary inside .button means the selector becomes .button-primary. Similarly for &-secondary. The base .button keeps its styles.
❓ layout
advanced2:00remaining
How does this nested Sass affect layout with Flexbox?
Given this Sass code:
.container {
display: flex;
.item {
flex: 1;
&:hover {
background: lightgray;
}
}
}
Attempts:
2 left
💡 Hint
Flexbox distributes space among children with flex: 1. &:hover applies styles on hover.
✗ Incorrect
display:flex on .container makes it a flex container. .item with flex:1 means all items share space equally. &:hover inside .item applies background color on hover.
❓ accessibility
expert3:00remaining
Which nested Sass code best supports keyboard focus styles accessibly?
You want to style a button and its focus state for keyboard users. Which Sass code correctly nests and uses :focus-visible for accessibility?
Options:
Attempts:
2 left
💡 Hint
Use :focus-visible to show focus outlines only when keyboard navigation is used.
✗ Incorrect
:focus-visible applies styles only when the element is focused via keyboard, improving accessibility by not showing outlines on mouse clicks. &:focus-visible nests this selector properly in Sass.