【问题标题】:Prefix a selector both as parent and intersection前缀选择器作为父级和交集
【发布时间】:2020-01-26 22:22:42
【问题描述】:

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

输入

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

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

输出

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

我希望选择器的前缀为“带空格”和“不带空格”。这可能吗?我可以使用 Less、Sass 或 Stylus。 谢谢!

【问题讨论】:

  • 为什么不将& 选择器也添加到.two...例如。 &.two, .two { .three { } }?

标签: css sass less stylus


【解决方案1】:

如果我正确理解你的问题,你可以像这样设置你的 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;
}

【讨论】:

  • 虽然这确实是我想要达到的效果,但我希望能够将一个块传递给mixin,并为该块的内容加上前缀.
  • 更新您的问题以更清楚。举一个你想要传递的block 的例子。现在,有点太模糊了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-07
  • 1970-01-01
  • 2016-08-22
  • 2011-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多