The & symbol represents the parent selector. It lets you refer to the current selector inside nested rules.
Click to reveal answer
beginner
How do you combine <code>&</code> with a pseudo-class like <code>:hover</code> in Sass?
You write &:hover inside a nested block. It means "apply styles when the parent element is hovered."
Click to reveal answer
beginner
Example: What CSS does this Sass produce?
.btn {
color: blue;
&:hover {
color: red;
}
}
It produces:
.btn {
color: blue;
}
.btn:hover {
color: red;
}
This means the button is blue normally and red when hovered.
Click to reveal answer
intermediate
Can you combine & with multiple pseudo-classes? For example, &:focus:hover?
Yes! You can combine multiple pseudo-classes after &. For example, &:focus:hover targets the parent element when it is both focused and hovered.
Click to reveal answer
beginner
Why is using & with pseudo-classes helpful in Sass?
It keeps your styles organized and readable by nesting related states inside the main selector. It avoids repeating the full selector and reduces errors.
Click to reveal answer
In Sass, what does &:hover mean inside a nested block?
AApply styles only on click
BApply styles to all child elements
CApply styles when the parent element is hovered
DApply styles to sibling elements
✗ Incorrect
&:hover targets the parent selector when it is hovered by the mouse.
Hint: Pseudo-classes always start with a colon after & [OK]
Common Mistakes:
Omitting colon before pseudo-class
Adding parentheses after pseudo-class
Using extra colon after pseudo-class
3. Given the Sass code:
.nav { color: black; &:hover { color: blue; } }
What color will the text inside <div class="nav"> be when hovered?
medium
A. Blue
B. Red
C. Black
D. No color change
Solution
Step 1: Understand base and hover styles
The base color for .nav is black. The hover pseudo-class changes color to blue.
Step 2: Determine hover effect
When the mouse pointer is over the .nav element, the color changes to blue as defined by &:hover { color: blue; }.
Final Answer:
Blue -> Option A
Quick Check:
Hover changes color to blue [OK]
Hint: Hover styles override base styles on mouse over [OK]
Common Mistakes:
Ignoring hover styles
Confusing base color with hover color
Assuming no style change on hover
4. Identify the error in this Sass code snippet:
.link { &hover { text-decoration: underline; } }
medium
A. Missing colon before pseudo-class hover.
B. Incorrect use of & symbol.
C. Pseudo-class hover should be uppercase.
D. Text-decoration property is invalid.
Solution
Step 1: Check pseudo-class syntax
Pseudo-classes must start with a colon (:), so hover should be :hover.
Step 2: Identify the error
The code uses &hover without colon, which is invalid syntax in Sass.
Final Answer:
Missing colon before pseudo-class hover. -> Option A
Quick Check:
Pseudo-classes need colon [OK]
Hint: Always put colon before pseudo-classes like :hover [OK]
Common Mistakes:
Omitting colon before pseudo-class
Assuming & alone is enough
Capitalizing pseudo-class names
5. You want to style a button so that when it is focused or hovered, its background changes to green. Which Sass code correctly combines & with multiple pseudo-classes?
hard
A. .button { &:hover &:focus { background: green; } }
B. .button { &hover, &focus { background: green; } }
C. .button { &:hover, &:focus { background: green; } }
D. .button { &:hover:focus { background: green; } }