Skip to content

Instantly share code, notes, and snippets.

@curder
Created October 14, 2017 13:29
Show Gist options
  • Save curder/3be58a411e207c03d57bc7b3d41f0791 to your computer and use it in GitHub Desktop.
Save curder/3be58a411e207c03d57bc7b3d41f0791 to your computer and use it in GitHub Desktop.
在SCSS中简单使用循环语句for/while/each
// for loop
@for $space from 1 through 12 {
.pt-#{$space} {
padding-top: 10px * $space;
}
.pb-#{$space} {
padding-bottom: 10px * $space;
}
$width: percentage(1 / $space);
.col-#{$space} {
width: $width;
}
}
// while loop
$num: 0;
@while( $num <= 12) {
$width: percentage(1 / $num);
.col-#{$num} {
width: $width;
}
$num: $num + 1;
}
// each loop
$white: #fff;
$black: #000;
$red: #f00;
$primary: #ccc;
$secondary: #333;
$colors: (
'white': $white,
'black': $black,
'red': $red,
'primary': $primary,
'secondary': $secondary
);
@each $color, $hex in $colors {
.text-#{$color} {
color: $hex;
}
.background-#{$color} {
background-color: $hex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment