使用';将sass列表转换为多个选择器';

使用';将sass列表转换为多个选择器';,sass,Sass,我头痛 我试图找到一个解决办法,但没有办法解决这个问题 我的代码几乎如下所示 @mixin test(){ &:after { content: 'yes'; } } $selectors:(); @for $i from 1 through 3 { $selectors: append($selectors, 'h'+$i); } #{$selectors} { @include test; } 我想把结果定为 h1:after, h2:after, h3

我头痛

我试图找到一个解决办法,但没有办法解决这个问题

我的代码几乎如下所示

@mixin test(){
  &:after {
    content: 'yes';
  }
}

$selectors:();
@for $i from 1 through 3 {
  $selectors: append($selectors, 'h'+$i);
}

#{$selectors} {
  @include test;
}
我想把结果定为

h1:after, h2:after, h3:after {
    content: 'yes';
}
但是我有

h1 h2 h3:after {
    content: 'yes';
}
SASS

%test{
  &:after {
    content: 'yes';
  }
}

@for $i from 1 through 3 {
  h#{$i}  { @extend %test; }
}
h1:after, h2:after, h3:after {
  content: 'yes';
}
输出CSS

%test{
  &:after {
    content: 'yes';
  }
}

@for $i from 1 through 3 {
  h#{$i}  { @extend %test; }
}
h1:after, h2:after, h3:after {
  content: 'yes';
}

更新

如果要使用代码,可以执行以下操作:

@mixin test(){
  &:after {
    content: 'yes';
  }
}

$selectors:();
@for $i from 1 through 3 {
  $selectors: append($selectors, ('h'+$i), comma);
}

#{$selectors} {
  @include test;
}

这是工作。而且很容易。谢谢你的回答。如果你知道,请再告诉我一次。这不可能像我的风格吗?我试着像其他语言一样使用join。但这不是工作。