Less isunit

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Less isunit()

The Less isunit() function takes a value as a parameter and returns TRUE if the value is a number in specified units provided as parameter otherwise, returns FALSE.

isunit() Function Example

Let's take an example to demonstrate the usage of isunit() function in Less file.

Create a Less file named "simple.less", having the following code:

Less file: simple.less

  1. div {  

  2.     font:        isunit(11px, px);    

  3.     background:  isunit(2.2%, px);  

  4.     border:      isunit(33px, rem);  

  5.     font:        isunit(4rem, rem);  

  6.     background:  isunit(56px, "%");  

  7.     border:      isunit(7.8%, '%');  

  8.     border:      isunit(1234, em);  

  9. }  

Now open the node.js command prompt and execute the following code: lessc simple.less simple.css

Less isunit function1

This will compile the "simple.less" file. A CSS file named "simple.css" will be generated.

For example:

Less isunit function2

The generated CSS "simple.css", has the following code:


Less isunit function3

  1. div {  

  2.   font: true;  

  3.   background: false;  

  4.   border: true;  

  5.   border: false;  

  6. }