’@规则’
Sass 的许多额外功能都以新 at 规则 的形式出现,它添加在 CSS 之上:
-
@use从其他 Sass 样式表加载 mixins、函数和变量,并将多个样式表中的 CSS 组合在一起。¥
@useloads mixins, functions, and variables from other Sass stylesheets, and combines CSS from multiple stylesheets together. -
@forward加载 Sass 样式表,并在使用@use规则加载样式表时使其 mixins、函数和变量可用。¥
@forwardloads a Sass stylesheet and makes its mixins, functions, and variables available when your stylesheet is loaded with the@userule. -
@import扩展了 CSS at 规则以从其他样式表加载样式、mixins、函数和变量。¥
@importextends the CSS at-rule to load styles, mixins, functions, and variables from other stylesheets. -
@mixin和@include可以轻松地重复使用样式块。¥
@mixinand@includemakes it easy to re-use chunks of styles. -
@function定义了可在 SassScript 表达式 中使用的自定义函数。¥
@functiondefines custom functions that can be used in SassScript expressions. -
@extend允许选择器相互继承样式。¥
@extendallows selectors to inherit styles from one another. -
@at-root将样式放入 CSS 文档的根目录中。¥
@at-rootputs styles within it at the root of the CSS document. -
@error导致编译失败并显示错误消息。¥
@errorcauses compilation to fail with an error message. -
@warn在不完全停止编译的情况下打印警告。¥
@warnprints a warning without stopping compilation entirely. -
@debug打印一条消息用于调试目的。¥
@debugprints a message for debugging purposes. -
诸如
@if、@each、@for和@while之类的流量控制规则控制是否发出样式或发出多少次样式。¥Flow control rules like
@if,@each,@for, and@whilecontrol whether or how many times styles are emitted.
Sass 对于 纯 CSS at 规则 也有一些特殊行为:它们可以包含 插值法,并且可以嵌套在样式规则中。其中一些,如 @media 和 @supports,还允许 SassScript 直接在规则本身中使用,无需插值。
¥Sass also has some special behavior for plain CSS at-rules: they can contain
interpolation, and they can be nested in style rules. Some of them, like
@media and @supports, also allow SassScript to be used directly in
the rule itself without interpolation.