当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > CSS优化:less优化CSS

CSS样式表
做网页中需要掌握的八个CSS布局技巧
CSS属性 - white-space 空白属性使用说明
用CSS构建iframe效果代码
用div+css解决出现水平滚动条问题
ul在Firefox和IE下的不同表现的解决方法
用css实现隐藏文本框
css实现行间距效果
研究了一下div+css的高度自适应问题
做网页字体大小参考 网页中同字号字体的不同单位对比列表
css 之 background-position-x
css实现兼容各个浏览器的技巧的代码
css中的行间距的代码
HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详解
scrollWidth,clientWidth与offsetWidth的区别
大家需要掌握的 html下SPAN和DIV的区别
布局用CSS+DIV的优点总结
纯CSS生成抗锯齿圆角的代码
IE6,IE7和firefox对DIV的支持区别
DIV+CSS布局的网站对网站SEO的影响分析
非常不错的关于IE与FireFox的js和css几处不同点[转自星火燎原]

CSS样式表 中的 CSS优化:less优化CSS


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 139 ::
收藏到网摘: n/a

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;
}