SASS-spiekbriefje
Een doorzoekbaar, afdrukbaar Sass / SCSS-naslagwerk — variabelen, nesten, @use modules, mixins, functies, control flow en ingebouwde modules. Gratis.
Variables
10$primary: #1d6f42;
$radius: 4px !default;
$theme: dark !global;
.box { $w: 10px; width: $w; }
$font-stack: 'Inter', sans-serif;
$gap: 8px * 2;
color: $primary;
$sizes: 4px, 8px, 16px;
$config: ('gap': 8px);
$on: true;
Nesting
9.card { .title { color: red; } }
.btn { &:hover { opacity: .8; } }
.btn { &.is-active {} }
.list { & + & { margin-top: 8px; } }
.menu { .dark & { color: #fff; } }
.box { font: { size: 14px; weight: 700; } }
.grid { > .col {} }
@media (min-width: 768px) { .col { width: 50%; } }
.a { color: red; .b & { color: blue; } }
Partials & modules
10_base.scss
@use 'base';
base.$primary;
@use 'base' as b;
@use 'base' as *;
@use 'theme' with ($primary: #000);
@forward 'buttons';
@forward 'buttons' as btn-*;
@forward 'src/list' hide list-reset;
@forward 'config' with ($gap: 4px !default);
Mixins
10@mixin reset { margin: 0; padding: 0; }
@include reset;
@mixin pad($x) { padding: $x; }
@include pad(8px);
@mixin pad($x: 4px) { padding: $x; }
@include pad($x: 12px);
@mixin shadow($a...) { box-shadow: $a; }
@mixin card { border: 1px solid; @content; }
@include card { color: red; }
@mixin on-dark { @content; }
Functions
9@function double($n) { @return $n * 2; }
width: double(8px);
@function pad($x: 4px) { @return $x; }
@function sum($a, $b) { @return $a + $b; }
@function clampn($n) { @if $n < 0 { @return 0; } @return $n; }
@use 'sass:math';
@function half($n) { @return math.div($n, 2); }
@function list-len($l) { @return list.length($l); }
margin: sum(4px, 8px);
Operators & math
10@use 'sass:math';
width: math.div(100%, 3);
width: 100% - 20px;
margin: 4px + 4px;
width: 2 * 8px;
$r: 10 % 3;
@if $a == $b {}
@if $a >= 768px {}
@if $a and $b {}
@if not $disabled {}
Control flow
9@if $on { display: block; }
@else if $alt { display: flex; }
@else { display: none; }
@each $c in red, green, blue {}
@each $name, $val in $map {}
@each $k, $v in ('sm': 4px, 'md': 8px) { .#{$k} { gap: $v; } }
@for $i from 1 through 3 {}
@for $i from 0 to 3 {}
@while $i > 0 { $i: $i - 1; }
Built-in modules
14@use 'sass:math'; math.floor(4.7)
math.ceil(4.1)
math.round(4.5)
math.percentage(math.div(1, 4))
@use 'sass:string'; string.to-upper-case('hi')
string.quote(hello)
@use 'sass:color'; color.adjust($c, $lightness: 10%)
color.scale($c, $lightness: 20%)
color.mix($a, $b, 50%)
@use 'sass:list'; list.length($l)
list.nth($l, 1)
@use 'sass:map'; map.get($m, 'gap')
map.merge($a, $b)
map.keys($m)
Placeholders & inheritance
9%card { border: 1px solid; }
.box { @extend %card; }
.alert { color: red; }
.error { @extend .alert; }
.note { @extend .alert !optional; }
%btn-base { padding: 8px; }
.btn-primary { @extend %btn-base; }
.btn-ghost { @extend %btn-base; }
@include card;
Interpolation & misc
12.icon-#{$name} { content: ''; }
width: calc(100% - #{$gap});
content: '#{$count} items';
--bs-#{$key}: #{$val};
$map: ('sm': 576px, 'md': 768px);
map.get($map, 'md')
@debug $value;
@warn 'deprecated';
@error 'invalid input';
// inline comment
/* block comment */
@import 'base';
Geen vermelding komt overeen met “:q”.
Over SASS-spiekbriefje
Deze Sass/SCSS-cheatsheet behandelt de preprocessor van syntaxis tot architectuur: variabelen, nesting, partials en modules, mixins, functies, operatoren en wiskunde, controlestructuren, ingebouwde modules, placeholders en overerving, en interpolatie met overige zaken.
Hij weerspiegelt hoe moderne Sass wordt geschreven — het modulesysteem @use en genamespacete ingebouwde modules naast de klassieke features — dus is hij even nuttig voor het onderhouden van een oudere @import-codebase als voor het schrijven van nieuwe module-gebaseerde stylesheets.
De cheatsheet is gratis en wordt client-side weergegeven. Filter elk fragment live met het zoekvak, spring naar een sectie via de vastgeplakte inhoudsopgave, klik op een fragment om het in je stylesheet te kopiëren en print de pagina voor een papieren SCSS-referentie.
Hoe gebruik je SASS-spiekbriefje
- Loop de secties door, van Variabelen en Nesting via Mixins tot Ingebouwde modules.
- Zoek op een feature zoals mixin, @use of map om het overzicht live te filteren.
- Spring naar Controlestructuren of Placeholders & overerving via de vastgeplakte zijbalk.
- Klik op een fragment of het kopieerpictogram om de SCSS in je stylesheet te kopiëren.
- Print de cheatsheet als je liever een papieren referentie hebt tijdens het refactoren van stijlen.