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

CSS样式表
简单学习CSS网页布局(初学者)
8个简单实用的CSS秘诀
Webjx收集基于CSS JS设计50款优秀的导航菜单
css word-break word-wrap 前台显示自动换行
css 自动换行 强制换行属性 (firefox+ie)
css 教学实例 漂亮的搜索框
CSS 折叠的菜单实现代码
关于html元素的 width属性无效果的解决方法
css 相对定位 绝对定位 浮动 分析
css 滑动门技术的介绍及实例分享
负边距创建自适应宽度的流体布局的实现方法
有利于SEO的DIV+CSS的命名规则小结
css盒子模型 css margin 外边框合并
css 优先级关系
input 文本框 文字垂直居中对齐 ie firefox
css margin-left在IE6下的问题的解决方法
IE8样式不正确显示问题
div中子div在firefox ie 水平居中对齐
css 不兼容性问题小结
CSS 3D立方体制作

CSS样式表 中的 CSS less优化


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 98 ::
收藏到网摘: 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;
}