Functions
5 methodsSass 颜色函数,用于调整亮度和混合颜色。在编译时对 Sass 颜色值进行操作。
display: flex | inline-flex返回在 HSL 亮度上增加 $amount(0%-100%)的颜色。
Returns
declaration
Example
css3
.row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
}display: grid返回在 HSL 亮度上降低 $amount(0%-100%)的颜色。
Returns
declaration
Example
css3
.layout {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}grid-template-columns: <track-list>混合两种颜色,$weight 表示使用 $color1 的比例。
Parameters
| Name | Type | Description |
|---|---|---|
| track-list | string | e.g. 'repeat(3, 1fr)' or '100px 1fr 2fr'. |
Returns
declaration
Example
css3
.gallery {
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}transform: <transform-functions>返回具有指定 alpha 通道(不透明度)的给定颜色。
Parameters
| Name | Type | Description |
|---|---|---|
| transform-functions | string | e.g. 'translateX(10px) rotate(45deg)'. |
Returns
declaration
Example
css3
.card {
transform: translateY(-4px) rotate(2deg);
transition: transform .2s ease;
}flex: <grow> <shrink> <basis>Shorthand for flex-grow, flex-shrink, and flex-basis on a flex item.
Parameters
| Name | Type | Description |
|---|---|---|
| grow | number | Grow factor. |
| shrink | number | Shrink factor. |
| basis | length | auto | Initial main size. |
Returns
declaration
Example
css3
.main { flex: 1 1 auto; }
.sidebar { flex: 0 0 200px; }Directives
4 methodsSass 控制指令 @mixin、@include 和 @extend,用于可复用样式和选择器继承。
calc(expression)定义可接受参数的可复用样式块。通过 @include 调用。
Parameters
| Name | Type | Description |
|---|---|---|
| expression | string | e.g. '100% - 80px' (spaces required around + and -). |
Returns
<length> | <percentage> | etc.
Example
css3
.box {
width: calc(100% - 2 * 16px);
font-size: calc(1rem + 0.5vw);
}var(<custom-property-name>, <fallback>?)包含之前定义的 mixin,可选传递参数。
Parameters
| Name | Type | Description |
|---|---|---|
| custom-property-name | <custom-property-name> | e.g. '--main-color'. |
| fallback | <declaration-value> | Optional value used if the property is not set. |
Returns
<declaration-value>
Example
css3
:root { --main: #3498db; }
.btn {
background: var(--main, #000);
}linear-gradient(<angle|side>, <color-stop-list>)继承另一规则或占位符的样式,将扩展选择器插入到源选择器旁边。
Parameters
| Name | Type | Description |
|---|---|---|
| angle|side | string | e.g. 'to right' or '45deg'. |
| color-stop-list | string | e.g. 'red, blue' or 'red 0%, blue 100%'. |
Returns
<image>
Example
css3
.banner {
background: linear-gradient(45deg, #ff8a00, #e52e71);
}radial-gradient(<shape> at <position>, <color-stop-list>)通过 @content 将样式块传递给 mixin;适用于媒体查询包装器。
Parameters
| Name | Type | Description |
|---|---|---|
| shape | string | e.g. 'circle' or 'ellipse'. |
| position | string | e.g. 'center' or '50% 50%'. |
| color-stop-list | string | e.g. 'white, black'. |
Returns
<image>
Example
css3
.halo {
background: radial-gradient(circle at center, #fff, #000);
}