日期:2014-01-19 浏览次数:21653 次
less官方网址:http://lesscss.org
下面就来引见下吧
less用变量 (variables),援用(mixins),表达式(operations),嵌套规则(nested rules)来扩展css开发
变量 (variables)
反复使用的值可以定义成变量的方式,方便更改哈
例子如下:
#header {
color: #4D926F;
}
h2 {
color: #4D926F;
}
@brand_color: #4D926F;
#header {
color: @brand_color;
}
h2 {
color: @brand_color;
}
援用(mixins)
在一个类中可以援用另一个类的名称做为该类的属性。
#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;
}
嵌套规则(nested rules)
以前我们开发的css的时候selector的承继都要写的很长 ,用less后。我们可以用更简约,直观的方式来写css
实例如下:
#header {
color: red;
}
#header a {
font-weight: bold;
text-decoration: none;
}
#header {
color: red;
a {
font-weight: bold;
text-decoration: none;
}
}
表达式(operations)
一些单元之间可能有些值要成比例,比如宽高,颜色值
我们都可以用表达式来计算实现
#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;
}