less官方網(wǎng)址:http://lesscss.org
下面就來(lái)介紹下吧
less用變量 (variables),引用(mixins),表達(dá)式(operations),嵌套規(guī)則(nested rules)來(lái)擴(kuò)展css開(kāi)發(fā)
變量 (variables)
重復(fù)使用的值可以定義成變量的形式,方便更改哈
例子如下:
#header { color: #4D926F;}h2 { color: #4D926F;}@brand_color: #4D926F;#header { color: @brand_color;}h2 { color: @brand_color;}
引用(mixins)
在一個(gè)類(lèi)中可以引用另一個(gè)類(lèi)的名稱(chēng)做為該類(lèi)的屬性。
#header { -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px;}#footer { -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px;}.rounded_corners { -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px;}#header { .rounded_corners;}#footer { .rounded_corners;}嵌套規(guī)則(nested rules)
以前我們開(kāi)發(fā)的css的時(shí)候selector的繼承都要寫(xiě)的很長(zhǎng) ,用less后。我們可以用更簡(jiǎn)潔,直觀的方式來(lái)寫(xiě)css
實(shí)例如下:
#header { color: red;}#header a { font-weight: bold; text-decoration: none;}#header { color: red; a { font-weight: bold; text-decoration: none; }}
表達(dá)式(operations)
一些單元之間可能有些值要成比例,比如寬高,顏色值
我們都可以用表達(dá)式來(lái)計(jì)算實(shí)現(xiàn)
#header { color: #333; border-left: 1px; border-right: 2px;}#footer { color: #222;}@the-border: 1px;@base-color: #111;#header { color: @base-color * 3; border-left: @the-border; border-right: @the-border * 2;}#footer { color: @base-color + #111;}
新聞熱點(diǎn)
疑難解答
圖片精選