scss 的 @each指令
实例代码
1 $numArray: 10, 20, 30, 40; 2 @each $propKey, $propVal in (m: margin, p: padding) { 3 @each $directionKey, $directionVal in (t: top, r: right, b: bottom, l: left) { 4 @each $num in $numArray { 5 .#{$propKey}#{$directionKey}-#{$num} { 6 #{$propVal}-#{$directionVal}: ($num) + px; 7 } 8 } 9 } 10 }
经过编译后,可以看作是
.mt10 { margin-top: 10px; } .mt20 { margin-top: 20px; } ... .ml40 { margin-left: 40px; } ... .pl40 { padding-left: 40px; }