关系运算符

关系运算符确定 数字 是否大于或小于彼此。它们会自动在兼容单位之间进行转换。

  • <expression> < <expression> 返回第一个 表达 的值是否小于第二个的值。

    ¥<expression> < <expression> returns whether the first expression’s value is less than the second’s.

  • <expression> <= <expression> 返回第一个 表达 的值是否小于或等于第二个值。

    ¥<expression> <= <expression> returns whether the first expression’s value is less than or equal to the second’s.

  • <expression> > <expression> 返回第一个 表达 的值是否大于第二个的值。

    ¥<expression> > <expression> returns whether the first expression’s value is greater than to the second’s.

  • <expression> >= <expression>,返回第一个 表达 的值是否大于或等于第二个值。

    ¥<expression> >= <expression>, returns whether the first expression’s value is greater than or equal to the second’s.

SCSS Syntax

@debug 100 > 50; // true
@debug 10px < 17px; // true
@debug 96px >= 1in; // true
@debug 1000ms <= 1s; // true

Sass Syntax

@debug 100 > 50  // true
@debug 10px < 17px  // true
@debug 96px >= 1in  // true
@debug 1000ms <= 1s  // true

无单位的数字可以与任何数字进行比较。它们会自动转换为该数字的单位。

¥Unitless numbers can be compared with any number. They’re automatically converted to that number’s unit.

SCSS Syntax

@debug 100 > 50px; // true
@debug 10px < 17; // true

Sass Syntax

@debug 100 > 50px  // true
@debug 10px < 17  // true

单位不兼容的数字无法进行比较。

¥Numbers with incompatible units can’t be compared.

SCSS Syntax

@debug 100px > 10s;
//     ^^^^^^^^^^^
// Error: Incompatible units px and s.

Sass Syntax

@debug 100px > 10s
//     ^^^^^^^^^^^
// Error: Incompatible units px and s.