变量:
条件表达式:
- 单独使用:
@bool:true; & when(@bool=true){ body{ color:red; } } & when(@bool=false){ body{ color:yellow; } }
- 用在类中:
.class(@a) when (@a>5px){ width:@a; } body{ .class(6px); }
- 常见判断函数:
iscolor // 是否是颜色值 isnumber // 是否是数值 isstring // 是否是字符串 iskeyword // 是否是关键词 isurl // 是否是url地址 -- @isnumber下: ispixel // 是否是像素 ispercentage // 是否是百分比 isem // 是否是em isunit // 是否是单位
- 单独使用:
递归调用:
面向对象:
- 封装:
- 继承:
- 重载:
- 使用一个参数:
- 代码:
.class(@color){ color:@color; } .class(@color;@background){ color:@color; background: @background; } body{ .class(red); }
- 输出:
body { color: red; }
- 代码:
- 使用多个参数:
- 代码:
.class(@color){ color:@color; } .class(@color;@background){ color:@color; background: @background; } body{ .class(red,blue); }
- 输出:
body { color: red; background: blue; }
- 代码:
- 默认参数:
- 命名空间:
- 代码:
.namespace(){ .class(){ color:red; background: blue; } } body{ .namespace(); .class(); }
- 输出:
body { color: red; background: blue; }
- 代码:
- 使用一个参数:
插件:
- test.js:
module.exports = { install: function(less, pluginManager, functions) { functions.add('pi', function(val) { return less.dimension(Math.PI); }); } };
- test.less:
@plugin "test.js"; body{ width:pi() * 2; }
- 输出:
body { width: 6.28318531; }
- test.js:
导入:
@import "test"; == @import "test.less";
文档更新时间: 2024-04-19 15:11 作者:lee