Original article: LESS Introduction And differences with Sass translated from: An Introduction To LESS, And Comparison To Sass Original Author: Jeremy Hixon please respect copyright, reprinted please indicate the source, thank you!
A month ago, I accidentally discovered LESS and began to use it firmly. CSS itself has never been a problem for me, but I'm curious about the idea of using variables to create something for my website or template along a color palette. Having a color disk that provides a fixed number of options can help me avoid color skipping from a fixed style.
It turns out that LESS -- and Sass -- functions are much more than that. LESS and Sass have some similarities in syntax, such as the following:
- Mixins -- class in the class;
- Parameter mixing-class that can pass parameters, just like a function;
- Nested rules-nested classes in the Class to reduce repeated code;
- Computation-mathematics is used in CSS;
- Color function-you can edit the color;
- Namespace-group style, which can be called;
- Scope -- modify the style locally;
- JavaScript assignment-use a JavaScript expression to assign values in CSS.
The main difference between LESS and Sass is their implementation method. LESSS is based on JavaScript, so it is processed on the client.
On the other hand, Sass is Ruby-based and then processed on the server. Many developers do not choose LESS because the JavaScript engine requires additional time to process code and then output modified CSS to the browser. There are many ways to do this. I chose to use LESS in the development process. Once the development is complete, I copy and paste the LESS output to a compressed file, and then to a separate CSS file to replace the LESS file. Another option is to use LESS. app to compile and compress your LESS files. Both options minimize your style output to avoid any problems that may arise because your browser does not support JavaScript. Although this is unlikely, it is always possible.
LESS Is More
Introduction
Introducing LESS in your project is simple:
1. Download less. js;
2. Create a file to put your style, such as style. less;
3. Add the following code to your HTML
<Link rel = "stylesheet/less" type = "text/css" href = "styles. less "> <script src =" less. js "type =" text/javascript "> </script>
Note the rel attribute of link. You need to use/less at the end of the attribute value to make LESS work. Then it is necessary to introduce scirpt after link. If you are using HTML5 syntax-why not? -- You can save type = "text/css" and type = "text/javascript ".
In fact, there is also a server-side LESS version. The simplest way to install LESS on the server is to use Node Package Manager (NPM, which is based on Node. js at first glance ).
Source: browser observation responsibility Editor: bluehearts
Introduction of LESS on the previous page and its differences with Sass [2]