📜  萨斯 |数值函数

📅  最后修改于: 2022-05-13 01:56:52.898000             🧑  作者: Mango

萨斯 |数值函数

就像 SASS字符串函数一样,SASS 提供了一组简单的函数来更改数值,并且这些值可以按照您希望的方式工作。请注意,可以为除“percentage()”之外的每个函数赋予 CSS 值描述符,例如“px”或“rem”。在这种情况下,SASS 将忽略这些单位,并且它们不会显示在结果中。

下表列出了 Sass 中的所有数值函数:

FunctionDescriptionExample
percentage(number)This method converts a unitless number to the percentage. It means, multiplies it by 100.percentage(2.5)
Output: 250
percentage(4em)
Output: syntax error
round(number)This method rounds the number to the nearest whole number.round(2.25)
Output: 2
round(2.5)
Output: 3
ceil(number)This method rounds the number up to the nearest whole number.ceil(2.25)
Output: 3
floor(number)This method rounds the number down to the nearest whole number.floor(2.25)
Output: 2
abs(number)This method returns the absolute value of the number.abs(2)
Output: 2
abs(-2)
Output: 2
min(numbers)This method returns the smallest value in the list of numbers.min(4, 5, -7, 8, 2)
Output: -7
max(numbers)This method returns the largest value in the list of numbers.max(4, 5, -7, 8, 2)
Output: 8
random()This method returns a random number in the range of [0, 1].random()
Output: 0.4965
random(limit)This method returns a random whole number in the range of [1, limit].random(4)
Output: 2.4652