This article answers the following questions for novice developers of front-end reference.
1, what is Sass and Less?
2. Why use CSS preprocessor?
3, Sass and Less comparison
4. Why did you choose to use Sass instead Less?
What is Sass and Less?
Sass and Less CSS preprocessor belong to, what is it CSS preprocessor do?
CSS preprocessor defines a new language, the basic idea is to use a specialized programming language for programming CSS adds some features, the CSS file is generated as a target, then developers will just use this language to encode work of CSS.
Converted into plain words, " specifically in a programming language, style of Web page design, and then converted to normal CSS file by the compiler to use for the project ."
Why use CSS preprocessor?
As a front-end developers, we all know, Js can be custom variables, and CSS is just a markup language, not a programming language, and therefore can not be custom variables, and so can not be quoted.
CSS has several specific following disadvantages:
- Grammar is not strong enough, such as writing can not be nested, leading to the development of modular need to write a lot of choices duplicate device;
- No reasonable style variable and reuse mechanism, such that the associated value to be repeatedly output in the form of logic literals, making it difficult to maintain.
This leads to a lot of us no reason to increase the workload on the job. CSS preprocessor used, providing style layer multiplexing mechanism CSS missing reduce redundant code, style code to improve maintainability. Greatly improving our development efficiency.
However, CSS preprocessor is not snake oil, CSS has the advantage of simplicity, to be used anywhere and debugging. Precompiled CSS steps to join, so we developed a workflow more links, debugging becomes more trouble. The bigger question is, precompiled descendant selectors likely to result in abuse.
So we measure the precompiled programs in the actual project, still have to think about than to bring additional maintenance overhead, CSS pre-processor has not been resolved more trouble.
Compare Sass and Less of
the difference
2, Less Sass use relatively simple
3, starting from the function, Sass slightly stronger than some of Less
①sass there are variables and scope.
- $ variable, like PHP;
- # $ {variable} like Ruby;
- global and local variables of the points, and has priority.
②sass concept of function;
- @function and @return and function parameters (as well as variable parameters) allows you to develop that package like js logic you want.
- @ mixin similar function but lacks the function of programming logic, more is to improve the reusability and modularity css code segment, the person with the most.
-ruby provides a very rich set of built native api.
③ Process Control:
- Condition: @if @ else;
- Loop through: @for @each @while
- Inheritance: @extend
- quote: @import
④ Data Structure:
- Type List = $ array;
- $ = Object Type Map;
remaining there string, number, function type, etc.
Less and Sass some similarities in syntax, such as those below:
1, mixed (Mixins are) - in class class;
2, mixing parameters - the parameters of the class can be passed, like function;
3, nested rule --Class nested class, thereby reducing code duplication;
4 , spend the mathematical calculation --CSS;
5, color capabilities - edit the color;
6, namespace (namespace) - grouping style, which can be invoked;
7, scope - local modification of the style;
. 8, the JavaScript assignment - an assignment expression using JavaScript in the CSS.
3, on learning tutorial, Sass tutorial better than LESS. In the tutorial is focused on domestic LESS LESS Chinese official website, while Sass Chinese tutorial slowly in the country is also more common.
This article answers the following questions for novice developers of front-end reference.
1, what is Sass and Less?
2. Why use CSS preprocessor?
3, Sass and Less comparison
4. Why did you choose to use Sass instead Less?
What is Sass and Less?
Sass and Less CSS preprocessor belong to, what is it CSS preprocessor do?
CSS preprocessor defines a new language, the basic idea is to use a specialized programming language for programming CSS adds some features, the CSS file is generated as a target, then developers will just use this language to encode work of CSS.
Converted into plain words, " specifically in a programming language, style of Web page design, and then converted to normal CSS file by the compiler to use for the project ."
Why use CSS preprocessor?
As a front-end developers, we all know, Js can be custom variables, and CSS is just a markup language, not a programming language, and therefore can not be custom variables, and so can not be quoted.
CSS has several specific following disadvantages:
- Grammar is not strong enough, such as writing can not be nested, leading to the development of modular need to write a lot of choices duplicate device;
- No reasonable style variable and reuse mechanism, such that the associated value to be repeatedly output in the form of logic literals, making it difficult to maintain.
This leads to a lot of us no reason to increase the workload on the job. CSS preprocessor used, providing style layer multiplexing mechanism CSS missing reduce redundant code, style code to improve maintainability. Greatly improving our development efficiency.
However, CSS preprocessor is not snake oil, CSS has the advantage of simplicity, to be used anywhere and debugging. Precompiled CSS steps to join, so we developed a workflow more links, debugging becomes more trouble. The bigger question is, precompiled descendant selectors likely to result in abuse.
So we measure the precompiled programs in the actual project, still have to think about than to bring additional maintenance overhead, CSS pre-processor has not been resolved more trouble.
Compare Sass and Less of
the difference
2, Less Sass use relatively simple
3, starting from the function, Sass slightly stronger than some of Less
①sass there are variables and scope.
- $ variable, like PHP;
- # $ {variable} like Ruby;
- global and local variables of the points, and has priority.
②sass concept of function;
- @function and @return and function parameters (as well as variable parameters) allows you to develop that package like js logic you want.
- @ mixin similar function but lacks the function of programming logic, more is to improve the reusability and modularity css code segment, the person with the most.
-ruby provides a very rich set of built native api.
③ Process Control:
- Condition: @if @ else;
- Loop through: @for @each @while
- Inheritance: @extend
- quote: @import
④ Data Structure:
- Type List = $ array;
- $ = Object Type Map;
remaining there string, number, function type, etc.
Less and Sass some similarities in syntax, such as those below:
1, mixed (Mixins are) - in class class;
2, mixing parameters - the parameters of the class can be passed, like function;
3, nested rule --Class nested class, thereby reducing code duplication;
4 , spend the mathematical calculation --CSS;
5, color capabilities - edit the color;
6, namespace (namespace) - grouping style, which can be invoked;
7, scope - local modification of the style;
. 8, the JavaScript assignment - an assignment expression using JavaScript in the CSS.
3, on learning tutorial, Sass tutorial better than LESS. In the tutorial is focused on domestic LESS LESS Chinese official website, while Sass Chinese tutorial slowly in the country is also more common.