1.变量(Variables)
@width: 10px;
@height: @width + 10px;
#header {
width: @width;
height: @height;
}
2.混合:将一组属性从一个规则集包含到另一个规则集的方法。
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
.bordered();
}
3.嵌套
#header {
color: black;
.navigation {
font-size: 12px;
}
.logo {
width: 300px;
}
}
4.运算:算数运算符可以对任何数字、颜色或变量进行运算。
@incompatible-units: 2 + 5px - 3cm;
@var: 50vh/2;
width: calc(50% + (@var - 20px));
5.转义:允许使用任何字符串作为属性或变量值
@min768: ~"(min-width: 768px)";
.element {
@media @min768 {
font-size: 1.2rem;
}
}
6.函数:转换颜色、处理字符串、算术运算等。
1.if:
@some: foo;
div {
margin: if((2 > 1), 0, 3px);
color: if((iscolor(@some)), @some, black);
}
//结果:
div {
margin: 0;
color: black;
}
2.boolean:
@bg: black;
@bg-light: boolean(luma(@bg) > 50%);
div {
background: @bg;
color: if(@bg-light, black, white);
}
result:
div {
background: black;
color: white;
}
7.命名空间和访问符