搜索文档
选择器变量
.less 代码
less@app: app; .@{app}{ color: red; } #@{app}{ color: pink; }编译后的 .css 文件
css.app { color: red; } #app { color: pink; }
属性变量
.less
less@bgc: background-color; @bgcolor: red; .@{app}{ @{bgc}: @bgcolor }编译后 .css
css.app { background-color: red; }
url 变量
.less
less// url 变量 @img: "../image/img"; @icon: "../image/icon"; .box { background: url("@{img}/bg.png"); background-image: url("@{icon}/bg.png"); }.css
css.box { background: url("../image/img/bg.png"); background-image: url("../image/icon/bg.png"); }
声明变量
.less
less@box: { width: 100px; height: 100px; background-color: red; } .app { @box(); }.css
css.app { width: 100px; height: 100px; background-color: red; }
变量运算
.less
less@width: 200px; @color: #111; .box { width: @width - 20; height: @width * 2; color: @color + #777; background-color: @color * 4; }.css
css.box { width: 180px; height: 400px; color: #888888; background-color: #444444; }注: 运算符两侧必须加空格
变量作用域
.less
less@let: @a; @a: 100%; .box { width: @let; @a: 9%; }.css
css.box { width: 9%; }原理:就近原则
