LESS 是一门CSS预编译语言,犹记得当初打算使用CSS预编译语言的时候,可选的有SASS、LESS、Stylus三门,恰好那个时候在学习bootstrap,bootstrap项目中样式就是less写的,今后就结下了于LESS的缘分。LESS使用的快一年的时间了。
下面简单的列举一下我最爱的三个LESS的特性:css
@color: #ccc; #header { color: @color; } h2 { color: @color; }
编译后html
#header { color: #ccc; } h2 { color: #ccc; }
.rounded-corners (@radius: 5px) { -webkit-border-radius: @radius; -moz-border-radius: @radius; -ms-border-radius: @radius; -o-border-radius: @radius; border-radius: @radius; } #header { .rounded-corners; } #footer { .rounded-corners(10px); }
编译后程序员
#header { -webkit-border-radius: 5px; -moz-border-radius: 5px; -ms-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px; } #footer { -webkit-border-radius: 10px; -moz-border-radius: 10px; -ms-border-radius: 10px; -o-border-radius: 10px; border-radius: 10px; }
#header { h1 { font-size: 26px; font-weight: bold; } p { font-size: 12px; a { text-decoration: none; &:hover { border-width: 1px } } } }
编译后web
#header h1 { font-size: 26px; font-weight: bold; } #header p { font-size: 12px; } #header p a { text-decoration: none; } #header p a:hover { border-width: 1px; }
这三个缘由我想足以让人爱上LESS了。可是这里须要注意的仍然是有些点:bootstrap
.class { filter: ~"ms:alwaysHasItsOwnSyntax.For.Stuff()" }
参考文章:
LESS 中文官网
LESS Getting startedless