Less Operations

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

Less Operations

Some arithmetical operations like addition (+), subtraction ( - ), multiplication ( * ), and division ( / ) are supported in Less. These operations can be done on any number, color and variable. It is time saving while working on variables because it is as simple as working on mathematics.

Let's take an example to demonstrate the usage of Less operations.

Create a HTML file named "simple.html", having the following data.

HTML file: simple.html

   

  1. <html>  
  2. <head>  
  3.    <title>Less Operations Example</title>  
  4.    <link rel="stylesheet" type="text/css" href="simple.css" />  
  5. </head>  
  6. <body>  
  7.    <h1>Less Operations Example</h1>  
  8.    <p class="myclass">Less facilitates you to customize, manage and reuse style sheet for web site.</p>  
  9. </body>  
  10. </html>  

 

Now create a file named "simple.less". It is similar to CSS file. The only one difference is that it is saved with ".less" extension.

Less file: simple.less

  1. @fontSize: 10px;  

  2. .myclass {  

  3.  font-size: @fontSize * 5;  

  4.  color: pink;  

  5. }    

Put the both file ?simple.html? and ?simple.less? inside the root folder of Node.js

Now, execute the following code: lessc simple.less simple.css

Less Less operations1

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

For example:

Less Less operations2

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

  1. .myclass {  

  2.   font-size: 50px;  

  3.   color: pink;  

Output

Less Less operations3