插值#{}
1 | @mixin set-value($side, $value) { |
编译1
2
3.demo {
margin-top: 15px;
}
用处无限大,等待你发掘。
运算
加法
1 | $box-width: 100px; |
1 | .demo { |
不同的单位类型相加会报错
减法
-
同理
乘法
*
同理
除法
/
同理
控制指令
@if
根据条件除处理样式块1
2
3
4
5
6
7
8
9
10
11
12@mixin none ($boolean: true) {
@if $boolean {
display: block;
}
@else {
display: none;
}
}
.demo {
@include none(false);
}
编译1
2
3.demo {
display: none;
}
@for 循环
1 | @for $i from <start> through <end> // 循环包含end数 |
$i
变量start
起始值end
结束值
1. through
1 | @for $i from 1 through 3 { |
编译1
2
3
4
5
6
7
8
9
10
11.demo1 {
margin-top: 10px;
}
.demo2 {
margin-top: 20px;
}
.demo3 {
margin-top: 30px;
}
2. to
1 | @for $i from 1 to 3 { |
编译1
2
3
4
5
6
7.demo1 {
margin-top: 10px;
}
.demo2 {
margin-top: 20px;
}
while 循环
只要…就…1
2
3
4
5
6
7
8$tot = 3;
@while $tot > 0 {
.demo#{$tot} {
margin-top: 10px * $tot;
}
$tot: $tot - 1;
}
编译1
2
3
4
5
6
7
8
9
10
11.demo3 {
margin-top: 30px;
}
.demo2 {
margin-top: 20px;
}
.demo1 {
margin-top: 10px;
}
each 循环
遍历一个列表1
@each $var in <list>
1 | $list: one two three; |
编译1
2
3
4
5
6
7
8
9
10
11.show-img .img-one {
background: url("/imgs/one.png");
}
.show-img .img-two {
background: url("/imgs/two.png");
}
.show-img .img-three {
background: url("/imgs/three.png");
}