我想在 SCSS Sass 版本 3 中使用迭代器和条件检查器动态生成非常具体的类名和属性。
如果能被一半整除,则在末尾加一半。如果仅 .25 后缀,则以 '1q' 为后缀 如果 .75 后缀,则以 '3q' 为后缀
例子:
// margin classes
// classes m-a-0 to m-a-5, 1/4 rems specified by 1q, half, 3q
// // m-a-1q is 1/4 rem, m-a-1-1q is i.25rem
.m- {
&a-0 {
margin: 1rem * 0;
}
&a-1q {
margin: 1rem * 0.25;
}
&a-half {
margin: 1rem * 0.5;
}
&a-3q {
margin: 1rem * 0.75;
}
&a-1 {
margin: 1rem * 1;
}
&a-1-1q {
margin: 1rem;
}
&a-1half {
margin: 1rem * 1.5;
}
&a-1-3q {
margin: 1rem * 1.75;
}
&a-2 {
margin: 1rem * 2;
}
&a-2-1q {
margin: 1rem * 2.25;
}
&a-2half {
margin: 1rem * 2.5;
}
&a-2-3q {
margin: 1rem * 2.75;
}
}
应该生成:
.m-a-0{margin:0rem}.m-a-1q{margin:0.25rem}.m-a-half{margin:0.5rem}.m-a-3q{margin:0.75rem}.m-a-1{margin:1rem} ...