LESS is a css pre processor which extends the css language with some additional new features like declaring variables, mixins, functions and other techniques that allow us to make CSS more maintainable and extendable.
Installation
To install LESS, first you are required to install node in your system. To install Node go through this link https://nodejs.org/en/ . Here we assume that the node is already installed in your system.
The most simplest way to install Less on the server is via npm, ie, node.js package manager, as:
after installing, invoke the compiler from the command-line:
It will output the complied CSS to stdout. Command to save the CSS result to a file of your choice:
$ lessc styles.less styles.css
|
Simple example of LESS:
index.html
<!DOCTYPE html>
<head>
<link rel = stylesheet href = style.css type = text/css />
</head>
<body>
<h3> Lorem Ipsum </h3>
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</body>
</html>
next step is to create a style.less file. This is similar to CSS with the only difference of the extension. Both the files .html and .less are required to be created inside the folder nodejs.
Style.less
@base-color: #809DE1;
@color: #E37E52;
h3{
color: @base-color;
}
p{
color: @color;
}
For compiling style.less file into style.css, use the following command:
lessc style.less style.css
|
When you will run the above command, the style.css will show the following code:
style.css
h3{
color: #809DE1;
}
p{
color: #E37E52;
}
Happy Coding :)
0 Comment(s)