我在SASS中有一个for循环,它循环遍历页面类,为每个模块插入一个分色符。例如:
@for $i from 1 through 4 { // the loop
.m0#{$i} .module-title{
background-color: nth($m_col_lvl_01_list, $i);
}
//- end loop
}它编译为:
.m01 .module-title{
background-color: green;
}
.m02 .module-title{
background-color: blue;
}
.m03 .module-title{
background-color: yellow;
}
.m04 .module-title{
background-color: orange;
}在我目前的任务中,它包含了.m00,有没有一种在循环中包含00的方法?
发布于 2017-08-22 17:16:38
我认为在for循环中使用0仍然可以实现您想要的结果。
$list: (green, blue, orange, red, yellow);
//loop from 0 to the length of the list which isn't hardcoded
@for $i from 0 to length($list) {
.m0#{$i} .module-title {
//simply add one to the loop index to get the correct list item
background-color: nth($list, $i + 1);
}
}这将编译为以下CSS
.m00 .module-title {
background-color: green;
}
.m01 .module-title {
background-color: blue;
}
.m02 .module-title {
background-color: orange;
}
.m03 .module-title {
background-color: red;
}
.m04 .module-title {
background-color: yellow;
}https://stackoverflow.com/questions/45789591
复制相似问题