为选择器同时作为父代和交集添加前缀

问题描述 投票:0回答:1

我知道标题不是很具描述性,所以我将展示我需要的行为的一个示例:

输入

@mixin superScopeMixin {
  /* ... */
}

.one {
  superScopeMixin {
    .two {
      .three {
        /* ... */
      }
    }
  }
}

输出

.one.two .three,
.one .two .three {
  /* ... */
}

我希望选择器的前面都带有“空格”和“没有空格”。这可能吗?我可以使用Less,Sass或Stylus。谢谢!

css sass less stylus
1个回答
0
投票

如果我正确理解了您的问题,则可以这样设置mixin:

@mixin superScopeMixin {
  &.two, .two {
    color: #fff;
    .three {
      color: purple;
    }
  }
}

.one {
  color: gray;
  @include superScopeMixin
}

哪个编译为:

.one {
  color: gray;
}
.one.two, .one .two {
  color: #fff;
}
.one.two .three, .one .two .three {
  color: purple;
}
© www.soinside.com 2019 - 2024. All rights reserved.