Nesting
Nest selectors for readability without creating fragile specificity.
What you will be able to do
- Keep nesting to two or three levels.
- Use & for hover, focus and modifiers.
- Do not nest just to avoid class names.
- Prefer flat utility classes where appropriate.
In plain English
Nesting mirrors the DOM but should stay shallow. The parent selector & refers to the outer selector, which is perfect for states and modifiers. Deep nesting creates long selectors and coupling.
.card {
padding: 16px;
&:hover { border-color: #2f74c0; }
&.is-featured { box-shadow: 0 8px 24px rgb(0 0 0 / 0.12); }
.title { font-weight: 700; }
}Your turn
EasyAdd a hover state
Use & inside .card to style :hover.
SCSS · starter
.card { }Check your understanding before moving on.
Knowledge checkQuestion 1
What does & refer to?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.