less is written based on nodejs
sass is written in ruby, and the node-sass package is used to solve the compilation problem
Variables in
less are defined in mixin
@less. Block
use:
lessc
command to compile less files. Method:
"mixin" attribute can only be based on existing style rules! You can use class selector and id selector in mixin:
.a,#b{
color: rebeccapurple;
}
.mixin-class{
.a();
}
.mixin-id{
#b();
}
Output:
.a,
#b {
color: rebeccapurple;
}
.mixin-class {
color: rebeccapurple;
}
.mixin-id {
color: rebeccapurple;
}
Note that when calling mixin, parentheses are optional:
.a() //此种写法和下面写法无区别
.a;
Mixin that does not output :
If you want to create a mixin, but you don't want the mixin to output in the generated css, you can add parentheses () after it:
.my-mixin{
color: black;
}
.my-other-mixin(){
background: wheat;
}
.class{
.my-mixin;
.my-other-mixin;
}
Output:
.my-mixin {
color: black;
}
//此处并没有输出 .my-other-mixin
.class {
color: black;
background: wheat;
}
less
Neutral extend
:
Here is a block called mixin
:
If multiple places in less are quoted mixin
:
Then there will be a lot of repetitive codes in the final generated css:
if there are a lot of mixin
middle codes, then the final generated repetitive codes will be more, we obviously don’t want this,solution:
Use
extend
Result: The
common style is extracted in one place a
separate style there
less
The loop
cycle
Look at an example, the principle is recursion: the
result:
less modular
Variables in sass use $
The mixin
wording of sass is different from less:
First of all, sass
mixin
must be displayed with a@mixin
declaration, and the othermixin
name is not preceded by a dot. For example, here is
@mixin block, which cannot be written as @mixin
. The mixin in block Less looks like both a class and a mixin.
When using sass, you need to add@include
node-sass
How to use command-line compilation
sass
In, use extend like this:
sass
The loop
cycle
sass writes a grid layout recursively. Note that sass is used for quoting variables #{$n}
, and less is used for quoting variables.@{n}
but! ! ! ! ! ! ! ! ! ! ! ! ! ! !
In fact, sass doesn't have to be so troublesome, because sass supports for loops!
sass modular
to sum up:
CSS preprocessor framework