基础语法:
变量、混合(Mixins)、运算、函数、作用域、嵌套规则、
变量
- [x] @
|
|
混合
[x] 基础用法:征用:把原有的样式克隆拿过来用,
- [ ]
加()
不被编译,可传参
123456789101112.public() {width: 100px;height: 100px;}.box1 {.public;}//结果.box1 {width: 100px;height: 100px;}
- [ ]
- [ ] `不加()`
- 当做样式给元素用
- 当做方法被别的方法征用
1234567891011121314151617
.public { width: 100px; height: 100px;}.box1 { .public;}//结果.public { width: 100px; height: 100px;}.box1 { width: 100px; height: 100px;}
[x] extend : 公用:和原来的选择器公用一套样式
需原来的选择器不加括号
|
|
[x] 命名空间和作用域
- 类似js中规则1234567891011@num:1;.box{@num:10;&:hover{z-index:@num;}}// 结果.box:hover {z-index: 10;}
- 类似js中规则
[x] !important
- IE中兼容性使用–各种样式中,你想让谁的优先级高时使用12345678910111213141516171819202122232425262728.public() {width: 100px;height: 100px;.link {width: 200px;height: 200px;}&:hover {background: #EEE;}}.box {.public !important;// 把public及子孙元素的样式都继承!important过来}// 结果:.box {width: 100px !important;height: 100px !important;}.box .link {width: 200px !important;height: 200px !important;}.box:hover {background: #EEE !important;}
- IE中兼容性使用–各种样式中,你想让谁的优先级高时使用
[x] 参数 : 设定形参数
[ ] arguments
1234567891011121314151617181920.transition(@property: all;@duration: 1s;@function: linear;@delay: 0s;) {transition: @arguments;-webkit-transition: @arguments;-moz-transition: @arguments;-ms-transition: @arguments;-o-transition: @arguments;}.box1 {.transition;}//结果.box1 {transition: all 1s linear 0s;-webkit-transition: all 1s linear 0s;-moz-transition: all 1s linear 0s;-ms-transition: all 1s linear 0s;-o-transition: all 1s linear 0s}
- [ ] **返回值**:执行方法后再执行其变量相当于返回值
12345678
.public(@x, @y) { @result: @x+@y;}.box { .public(10, 20); z-index: @result;}
[x] 条件
[ ] 常用的条件运算符:>、>=、<、<=、=;
1234567891011121314151617181920.public(@x) when (@x<10) and (@x>0) {background: red;}.public(@x) when (@x>=10) {background: green;}.public(@x) when (@x<=0) {background: blue;}.box {.public(8);}//结果.box {backg round: red}[ ] 常用的IS函数:iscolor、isnumber、isstring、iskeyword、isurl、ispixel、ispercentage…
12345678910111213141516.public(@x) when (iscolor(@x)) {background: red;}.public(@x) when (isnumber(@x)) {background: green;}.box {.public(#123234);}// 结果.box {background: red}
循环嵌套(递归)
- 应用于多栏布局栅格系统
|
|
通过+、+_属性融合到一起
|
|
连字符
[x] 多个&
12345678910111213141516.box {width: 100px;height: 50px;& &-top {font-size: 15px;}}//结果.box {width: 100px;height: 50px}.box .box-top {font-size: 15px}[x] 1个&
- [x] 使用&倒置(不常用)
导入
- (reference) 不编译公共库内的方法123456@import (reference) "common";.box {.center; //公共方法width: 100px;height: 100px;}