Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

less

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?

like image 835
Kirkland Avatar asked Jul 05 '13 18:07

Kirkland


People also ask

How do you write less in CSS?

Create a stylesheet with . less extension and link it in your document using the rel="stylesheet/less" attribute. You are all set and can compose styles within the . less .

How do you round a number in HTML?

round() method rounds a number to the nearest integer. 2.49 will be rounded down (2), and 2.5 will be rounded up (3).

How do you use less function?

Description. LESS maps JavaScript code with manipulation of values and uses predefined functions to manipulate HTML elements aspects in the style sheet. It provides several functions to manipulate colors such as round function, floor function, ceil function, percentage function etc.


1 Answers

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)
like image 94
Paul Avatar answered Oct 19 '22 02:10

Paul