📜  SASS |内省功能

📅  最后修改于: 2021-09-01 01:28:47             🧑  作者: Mango

SASS 自省功能允许您检查 SASS 本身的状况。您在制作样式表时不能使用它们,但它们对于了解当某些东西无法按照您想要的方式工作时发生了什么至关重要。

下表包含了 SASS 中的所有内省函数:

Function Description Example
variable-exists($name) This method returns a Boolean value that represent whether the given variable exists, either globally or locally. $x: 40px;
variable-exists($x)
Output: true
variable-exists($y)
Output: false
global-variable-exists($name) This method returns a Boolean value that represent whether the given variable exists globally. $x: 40px;
global-variable-exists($x);
Output: true
mixin-exists($name) This method returns a Boolean value that represent whether the given mixin exists. @mixin text-color {color: blue; }
Output: true
inspect($value) This methods returns the value as it is given by SASS. inspect(54)
Output: “54”
type-of($value) This methods returns a string that represent the SASS data type of the value. type-of(5 6 4 7 8 9)
Output: “list”
unit(number) This methods returns the unit associated with the number, or a null string if the number is unitless. $x: 40px;
unit($x);
Output: “px”
$x: 40;
unit($x);
Output: “”
unitless($number) This methods returns a Boolean value that represent whether the given number has a unit associated with it or not. $x: 40px;
unitless($x);
Output: false
comparable($number1, $number2) This methods returns a Boolean value that represent whether the given numbers can be added, subtracted or compared. comparable(2em, 7em)
Output: true
comparable(2em, 4px)
Output: false
comparable(2em, 7)
Output: true