Variables
less
定义变量的符号是@
,sass
定义变量符号是$
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @images: "../img"; body { color: #444; background: url("@{images}/white-sand.png"); } @property: color; .widget { @{property}: #0ee; background-@{property}: #999; } @mySelector: banner; .@{mySelector} { font-weight: bold; line-height: 40px; margin: 0 auto; }
|
Mixins
less
的mixin
比sass
更简洁。
1 2 3 4 5 6 7
| .a, #b {color: red;} .mixin-class { .a; } .mixin-id { #b(); }
|
1 2 3 4 5 6 7 8 9 10
| .my-mixin { color: black; } .my-other-mixin() { background: white; } .class { .my-mixin; .my-other-mixin; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| .border-radius(@radius: 5px) { border-radius: @radius; }
.mixin() { @width: 100%; @height: 200px; } .caller { .mixin(); width: @width; height: @height; }
|
Extend
1 2 3 4 5 6 7 8 9 10
| .a:extend(.b) {}
.a { &:extend(.b); }
.e:extend(.f) {} .e:extend(.g) {}
.e:extend(.f, .g) {}
|
Import