Sass
Nesting
Mirror HTML structure and use the parent selector with &.
By EZ4Code Team
nestingsyntax
Code
.nav {
background: #333;
ul {
list-style: none;
margin: 0;
}
li {
display: inline-block;
a {
color: #fff;
text-decoration: none;
&:hover {
color: #1976d2;
}
}
}
> .logo { font-weight: bold; }
}Explanation
Sass nesting mirrors HTML structure inside selectors, improving readability. The & always refers to the parent selector, so &:hover compiles to .nav li a:hover. Deep nesting can bloat output, so keep it shallow and use child combinators where appropriate.
More Sass Snippets
Variables
Store colors, spacing, and breakpoints in Sass variables.
Mixins
Create reusable style groups with arguments and defaults.
Extend & Placeholders
Share styles across selectors with @extend and %placeholders.
Partials & @use
Split stylesheets into partials and load them with @use.
Functions
Define custom functions that return computed values.
Control Directives
Generate styles with @for, @each, and @if.