Sass
Functions
Define custom functions that return computed values.
By EZ4Code Team
functionslogic
Code
@function rem($px, $base: 16px) {
@return ($px / $base) * 1rem;
}
@function strip-unit($value) {
@return $value / ($value * 0 + 1);
}
.title {
font-size: rem(24px); // 1.5rem
padding: rem(16px);
}
.container {
max-width: rem(960);
}
// Built-in functions: lighten, darken, transparentize,
// mix, map-get, str-length, unit, etc.Explanation
@function defines custom logic that returns a single value, useful for unit conversions and calculations. Functions differ from mixins in that they produce values, not CSS rules. Combined with built-ins like lighten and map-get, they make stylesheets programmable.
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.
Extend & Placeholders
Share styles across selectors with @extend and %placeholders.
Partials & @use
Split stylesheets into partials and load them with @use.
Control Directives
Generate styles with @for, @each, and @if.