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

青春壹個敷衍的年華 提交于 2019-11-30 14:42:01

问题


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".



来源:https://stackoverflow.com/questions/17495302/can-numbers-be-rounded-math-term-using-less-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!