1、变量
使用 @ 来定义变量
2、混合(Mixins)
混合可以将一个定义好的 class A 轻松的引入到另一个class B中,从而简单实现class B继承class A中的所有属性。我们还可以带参数地调用,就像使用函数一样。
.rounded-corners (@radius: 5px) {
border-radius: @radius;
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
}
#header {
.rounded-corners;
}
#footer {
.rounded-corners(10px);
}
3、嵌套(Nesting)
#header { color: black;
.navigation { font-size: 12px }
.logo { width: 300px;
&:hover { text-decoration: none }
}
}
4、运算(Operations)
@base: 5%;
@filler: @base * 2;
@other: @base + @filler;
color: #888 / 4;
background-color: #112244 + #111;
height: 100% / 2 + @filler;
5、calc() 特例
@var: 50vh/2;
width: calc(50% + (@var - 20px));
6、函数(Functions)
Less 内置了多种函数用于转换颜色、处理字符串、算术运算等
@base: #f04615;
@width: 0.5;
.class {
width: percentage(@width);
color: saturate(@base, 5%);
background-color: spin(lighten(@base, 25%), 8);
}
标题7、作用域(Scope)
@var: red;
#page {
@var: white;
#header {
color: @var; /*white*/
}
}
8、注释(Comments)
块注释和行注释都可以使用:
标题9、导入(Importing)
@import "lib.less";
@import "lib";
@import "lib.css";