【发布时间】:2020-03-31 17:09:04
【问题描述】:
我在 .scss 中使用 angular,我想知道如何在 .scss 中执行以下 .less 代码。
HTML
<span class="flag-icon-{{territoryId}}"></span>
CSS
.flag-icon-@{country} {
//@country being the {{territoryId}} from above
}
这可能吗?
【问题讨论】:
我在 .scss 中使用 angular,我想知道如何在 .scss 中执行以下 .less 代码。
HTML
<span class="flag-icon-{{territoryId}}"></span>
CSS
.flag-icon-@{country} {
//@country being the {{territoryId}} from above
}
这可能吗?
【问题讨论】:
HTML
<span class="flag-icon-{{territoryId}}"></span>
scss 文件
$country-collection: ('india', 'usa', 'germany', 'pakistan');
@for $country from 0 to length($country-collection) {
.flag-icon-#{$country} {
color: red;
}
}
【讨论】:
谢谢Sayooj VR:https://stackoverflow.com/users/10647431/sayooj-v-r
我尝试了你的上述方法,但它似乎没有用,但它让我更了解了我可以用 scss 做什么,我设法用下面的代码弄明白了(哇哦!):
HTML
<span class="flag-icon-{{territoryId}}"></span>
SCSS
$country-collection: ('india', 'usa', 'germany', 'pakistan');
@each $country in $country-collection {
.flag-icon-#{$country} {
color: red
}
}
@for 似乎由于某种原因(不知道为什么)没有工作,所以我尝试了一种不同的循环技术,使用 @each 方法,并且 walaaaah 它工作了!
@each 的文档在这里:https://sass-lang.com/documentation/at-rules/control/each
【讨论】: