Can numbers be rounded (math term) using LESS CSS?

2019-02-08 06:53发布

问题:

LESS CSS = http://lesscss.org/

I declared a variable, like this... @height: 30px

Then I used a simple calculation, like this... line-height: @height * .666

It returns 19.98px but I wanted an even 20px

So, does LESS CSS have a way to round numbers up or down?

回答1:

Yes they can:

line-height: ceil(@height * .666);      // 20px (round up)
line-height: floor(@height * .666);    // 19px (round down)
line-height: round(@height * .666);     // 20px (round to closest integer)
line-height: round(@height * .666, 1);  // 20.0px (round to 1 decimal place)


回答2:

http://lesscss.org/functions/ for a list of the lesscss functions, floor is included under the heading "Math functions".



标签: less