Sass
Extend & Placeholders
Share styles across selectors with @extend and %placeholders.
By EZ4Code Team
extendplaceholders
Code
%message {
padding: 10px;
border-radius: 4px;
border: 1px solid transparent;
}
.success { @extend %message; color: green; border-color: lightgreen; }
.error { @extend %message; color: red; border-color: lightcoral; }
.warning { @extend %message; color: orange; border-color: #ffc107; }
// Compiles selectors together to avoid duplication:
// .success, .error, .warning { padding: 10px; ... }Explanation
@extend shares styles by grouping selectors that share a base, producing compact output. Placeholder selectors (%name) stay out of the CSS unless extended. Use @extend for closely related variants; prefer mixins when arguments or independent output are needed.
More Sass Snippets
Variables
Store colors, spacing, and breakpoints in Sass variables.
Nesting
Mirror HTML structure and use the parent selector with &.
Mixins
Create reusable style groups with arguments and defaults.
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.