Recall & Review
beginner
What does the
& symbol represent in Sass?The
& symbol represents the parent selector. It lets you refer back to the current selector inside nested styles.Click to reveal answer
beginner
How would you write a hover style for a button using the parent selector
& in Sass?You write it like this:<br>
button {<br> &:hover {<br> color: red;<br> }<br>}<br>This means: when the button is hovered, change its color to red.Click to reveal answer
intermediate
Can you use <code>&</code> to create a modifier class like <code>.btn-primary</code> inside <code>.btn</code>?Yes! You can write:<br>
.btn {<br> &-primary {<br> background: blue;<br> }<br>}<br>This creates a class .btn-primary with the styles inside.Click to reveal answer
intermediate
What happens if you use
& inside a nested selector like .menu > li?The
& will be replaced by the full parent selector. For example:<br>.menu {<br> > li {<br> color: green;<br> }<br>}<br>means .menu > li in CSS.Click to reveal answer
beginner
Why is using
& helpful in writing Sass?It helps keep your code DRY (Don't Repeat Yourself). You can write nested styles that relate to the parent without repeating the full selector. It makes your code cleaner and easier to maintain.
Click to reveal answer
In Sass, what does
&:hover inside a selector block do?✗ Incorrect
&:hover means the hover state of the current parent selector.How would you write a nested class
.card-active inside .card using &?✗ Incorrect
Using
&-active appends '-active' to the parent selector .card.What will this Sass code compile to?<br>
.nav { > li { color: red; } }✗ Incorrect
The
> li means direct child li of .nav.Can
& be used multiple times inside nested selectors?✗ Incorrect
& can be used multiple times and always means the parent selector.Which of these is a benefit of using
& in Sass?✗ Incorrect
& helps avoid repeating selectors and keeps your Sass code cleaner.Explain how the parent selector
& works in Sass and give an example of its use.Think about how you write hover styles or modifier classes inside a main class.
You got /3 concepts.
Describe a situation where using
& in Sass helps keep your code cleaner and easier to maintain.Consider writing styles for buttons with hover and active states.
You got /3 concepts.