sass-site/source/documentation/operators/relational.md

54 lines
1.6 KiB
Markdown
Raw Normal View History

2023-06-06 20:28:10 +02:00
---
title: Relational Operators
introduction: >
2023-06-09 03:44:39 +02:00
Relational operators determine whether
[numbers](/documentation/values/numbers) are larger or smaller than one
another. They automatically convert between compatible units.
2023-06-06 20:28:10 +02:00
---
2023-06-09 03:44:39 +02:00
2023-06-22 20:38:01 +02:00
* `<expression> < <expression>` returns whether the first [expression][]'s value
is less than the second's.
* `<expression> <= <expression>` returns whether the first [expression][]'s
value is less than or equal to the second's.
* `<expression> > <expression>` returns whether the first [expression][]'s value
is greater than to the second's.
* `<expression> >= <expression>`, returns whether the first [expression][]'s
value is greater than or equal to the second's.
2023-06-06 20:28:10 +02:00
2023-06-22 20:38:01 +02:00
[expression]: /documentation/syntax/structure#expressions
2023-06-06 20:28:10 +02:00
{% codeExample 'relational', false %}
@debug 100 > 50; // true
@debug 10px < 17px; // true
@debug 96px >= 1in; // true
@debug 1000ms <= 1s; // true
===
@debug 100 > 50 // true
@debug 10px < 17px // true
@debug 96px >= 1in // true
@debug 1000ms <= 1s // true
{% endcodeExample %}
2023-06-22 20:38:01 +02:00
Unitless numbers can be compared with any number. They're automatically
converted to that number's unit.
2023-06-06 20:28:10 +02:00
{% codeExample 'unitless-numbers', false %}
@debug 100 > 50px; // true
@debug 10px < 17; // true
===
@debug 100 > 50px // true
@debug 10px < 17 // true
{% endcodeExample %}
2023-06-22 20:38:01 +02:00
Numbers with incompatible units can't be compared.
2023-06-06 20:28:10 +02:00
{% codeExample 'incompatible-units', false %}
@debug 100px > 10s;
// ^^^^^^^^^^^
// Error: Incompatible units px and s.
===
@debug 100px > 10s
// ^^^^^^^^^^^
// Error: Incompatible units px and s.
{% endcodeExample %}