Tài liệu tham khảo nhanh SASS
Tài liệu tham khảo Sass / SCSS có thể tìm kiếm và in được — biến, nesting, module @use, mixin, hàm, control flow và module tích hợp sẵn. Miễn phí.
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';
Không có mục nào khớp với “:q”.
Giới thiệu về Tài liệu tham khảo nhanh SASS
Bảng tra cứu Sass / SCSS này bao gồm bộ tiền xử lý từ cú pháp đến kiến trúc: biến, lồng nhau, partial và module, mixin, hàm, toán tử và phép tính, luồng điều khiển, các module dựng sẵn, placeholder và kế thừa, cùng interpolation với các mục linh tinh khác.
Nó phản ánh cách Sass hiện đại được viết — hệ thống module @use và các module dựng sẵn có namespace cùng với các tính năng cổ điển — nên vừa hữu ích cho việc bảo trì codebase @import cũ vừa hữu ích cho việc viết stylesheet mới dựa trên module.
Bảng này miễn phí và hiển thị phía client. Lọc mọi đoạn mã trực tiếp bằng ô tìm kiếm, nhảy đến một phần từ mục lục cố định, nhấp vào bất kỳ đoạn mã nào để sao chép vào stylesheet của bạn và in trang ra cho một tài liệu tham khảo SCSS trên giấy.
Cách sử dụng Tài liệu tham khảo nhanh SASS
- Lướt qua các phần, từ Variables và Nesting qua Mixins đến Built-in modules.
- Tìm một tính năng như mixin, @use hoặc map để lọc bảng trực tiếp.
- Nhảy đến Control flow hoặc Placeholders & inheritance qua thanh bên cố định.
- Nhấp vào một đoạn mã hoặc biểu tượng sao chép của nó để sao chép SCSS vào stylesheet của bạn.
- In bảng nếu bạn thích tài liệu tham khảo trên giấy khi tái cấu trúc style.