LESS - Convert Function


Advertisements

Description

A number is converted from one unit to another. It consists two arguments; first argument passes number along with unit and second argument contain units. The number is converted when the unit is compatible. If the first argument is unchanged then the unit is not compatible.

Example

Below is the stylesheet file saved with extension .less; this is similar to a CSS file.

style.less

body {
   meter:convert(10cm, mm);
   time:convert(3s, "ms");
   no-unit:convert(5, mm);
}

You can compile the style.less file to style.css by using the following command −

lessc style.less style.css

Execute the above command; it will create the style.css file automatically with the following code −

style.css

body {
   meter: 100mm;
   time: 3000ms;
   no-unit: 5;
}
less_misc_functions.htm
Advertisements