当 body class 存在时,由 LESS Mixin 应用的 Alter CSS?

Alter CSS applied by LESS Mixin when body class is present?

我有一个 LESS mixin。当我将它应用于一个元素时,如果存在主体 class,我希望它的样式略有不同。

这个:

.mixin() {
  font-weight: bold;
  color: red;
}

.element {
  .mixin()
}

Outputs to this:

.element {
  font-weight: bold;
  color: red;
}

But I also want this to be outputted:

.body-class .element {
  color: blue;
}

你可以这样定义你的混合:

.mixin() {
  font-weight: bold;
  color: red;

  .body-class & {
    color: blue;
  }
}