Sass
Operators
Use arithmetic, relational, and equality operators in Sass.
By EZ4Code Team
operatorsmath
Code
$base: 16px;
.container {
width: 100% - 20%; // 80%
padding: $base * 2; // 32px
margin: ($base / 2); // 8px (division needs parens)
font-size: $base + 2px; // 18px
}
// Relational and equality operators in conditions
$mode: dark;
$width: 800px;
@if $mode == dark and $width > 600px {
.box { background: #333; }
}
// Color arithmetic
$color: #3498db;
.lighter { background: $color + #111; } // lighten via mathExplanation
Sass supports arithmetic (+ - * / %), relational (< > <= >=), and equality (== !=) operators, plus and/or/not for booleans. Division now needs parentheses or the math.div function to disambiguate from CSS. Operators enable calculations and conditional logic directly in stylesheets.
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.
Functions
Define custom functions that return computed values.