CSS Nesting Selectors
Use native CSS nesting to organize selectors hierarchically without preprocessor dependencies for cleaner stylesheets.
Code
.card {
padding: 1rem;
border-radius: 8px;
& .title {
font-size: 1.25rem;
font-weight: bold;
}
&:hover {
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
}CSS Nesting Selectors
Use native CSS nesting to organize selectors hierarchically without preprocessor dependencies for cleaner stylesheets.
Code
.card {
padding: 1rem;
border-radius: 8px;
& .title {
font-size: 1.25rem;
font-weight: bold;
}
&:hover {
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
}
Explanation
Native & nesting groups child selectors under a parent so stylesheets read hierarchically without a preprocessor. Expected behavior: the nested rules match with the same specificity as if they were written out flat. Caveat: without &, a nested type selector is implicitly descendant-scoped, which can broaden or narrow matches unexpectedly.
Interactive Tools for This Topic
Aspect Ratio CalculatorSimplify a width-to-height ratio, show its decimal value, and derive a matching height for a new width.Border Radius PreviewPreview four-corner border-radius values on a live box and copy the generated shorthand border-radius CSS declaration.Box Shadow GeneratorBuild CSS box-shadow values with offset, blur, spread, color, opacity, and inset controls, with a live preview of the result.CSS Color Name LookupTranslate between CSS keyword color names and hex values with RGB and HSL conversions, exact name matching, and nearest-color suggestions.
Report a problem with this exampleOpens a pre-filled issue on GitHub.