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