产生所需结果的代码如下所示:
$stylethemes: (
(15, bold, red),
(12, normal, blue)
);
@for $i from 1 through length($stylethemes) {
.theme#{$i} {
font-size: nth(nth($stylethemes, $i), 1);
font-weight: nth(nth($stylethemes, $i), 2);
color: nth(nth($stylethemes, $i), 3);
}
}
但是,您会发现这并不是特别灵活。您最好使用属性/值的映射,这样您就不必保证特定的顺序:
$stylethemes: (
(font-size: 15, font-weight: bold, color: red),
(font-size: 12, font-weight: normal, color: blue)
);
@for $i from 1 through length($stylethemes) {
.theme#{$i} {
@each $prop, $val in nth($stylethemes, $i) {
#{$prop}: $val;
}
}
}
或者
$stylethemes: (
theme1: (font-size: 15, font-weight: bold, color: red),
theme2: (font-size: 12, font-weight: normal, color: blue)
);
@each $theme, $properties in $stylethemes {
.#{$theme} {
@each $prop, $val in $properties {
#{$prop}: $val;
}
}
}