Front-end

Less中的循环(each方式)

用搜索工具得到的结果基本都是使用 when的方式,其实自从3.7.0 起官方提供了 each函数来遍历 Less 大概相当于CSS 参考 less官方文档

用搜索工具得到的结果基本都是使用 when的方式,其实自从3.7.0 起官方提供了 each函数来遍历

Less

@primary: blue;
@danger: red;
@warning: yellow;
@success: green;
@colors: primary, danger, warning, success;
each(@colors, {
  .bg-@{value} {
    background-color: @@value;
  }
})
less

大概相当于CSS

.bg-primary {
  background-color: blue;
}
.bg-danger {
  background-color: red;
}
.bg-warning{
  background-color: yellow;
}
.bg-success {
  background-color: green;
}
css

参考

评论