Less 如何在另一个类中使用较少的资源应用连接的类?

Less 如何在另一个类中使用较少的资源应用连接的类?,less,Less,假设我有以下较少的设置: .box { border: 1px solid #333; &.error { background-color: Red; } } 如果我想声明另一个应用了.box.error完整样式的类,例如.error-box,那么正确的语法是什么 如果我使用: .error-box { .box.error; } 我得到的只是红色背景,没有边框。我尝试了许多不同的组合,但总是出现语法错误。我插入了您的less,因此: .box {

假设我有以下较少的设置:

.box {
 border: 1px solid #333;
 &.error {
  background-color: Red;        
 }
}
如果我想声明另一个应用了.box.error完整样式的类,例如
.error-box
,那么正确的语法是什么

如果我使用:

.error-box {
 .box.error;
}

我得到的只是红色背景,没有边框。我尝试了许多不同的组合,但总是出现语法错误。

我插入了您的less,因此:

.box {
   border: 1px solid #333;
   &.error {
      background-color:red; 
   }
}

.error-box {
    .box;
}
CSS输出是这样的:

.box {
  border: 1px solid #333;
}
.box.error {
  background-color: red;
}
.error-box {
  border: 1px solid #333;
}
.error-box.error {
  background-color: red;
}
是否希望.error box类单独接收这两种样式?我能想到的唯一方法是:

.error-bg {
    background:red;
}

.box {
    border:1px solid #333;
    &.error {
        .error-bg;
    }
}

.error-box {
    .box;
    .error-bg;
}