Title
Body text styled from a nested rule.
The h3 and p rules live inside the .nest-card block.
If you searched css nesting or the & selector, modern browsers now nest rules natively with no Sass build step. This tutorial shows nesting children, states, and media queries with copy-ready snippets.
Keep component styles together without repeating the parent class.
Body text styled from a nested rule.
The h3 and p rules live inside the .nest-card block.
.card {
padding: 1rem;
h3 { margin: 0; }
p { color: #64748b; }
}Use & for hover, focus, and compound selectors.
The &:hover rule is nested inside .nest-btn.
.btn {
background: #2563eb;
&:hover { background: #1d4ed8; }
&.is-active { background: #7c3aed; }
}Co-locate responsive rules with the component.
The nested @media changes padding on wider screens.
.panel {
padding: 1rem;
@media (min-width: 40rem) {
padding: 2rem;
}
}