5

这是我最终想要做的事情:

.books, .dvds, .magazines {
  article &.books {
    /* Wanting the selector to only be ".books article" */
  }
  article {
    /* Can apply to any of the `article` tags under .books, .dvds and .magazines */
  }
}

我有一些嵌套的选择器,而不是打破一个新的选择.books article器,我想让它们保持嵌套,但仍然只有.article.books

我确实尝试过,它有效,但输出是.books.books article,这是多余的,让我畏缩:

.books, .dvds, .magazines {
    &.books article {
        /* Outputs ".books.books article, .dvds.books article, .magazines.books article"...boooo, hisssss */
    }
}
4

1 回答 1

20

更像是什么:

article {

  .books &,
  .dvds &,
  .magazines & {
    /* book, dvd, magazine shared stuff */
  }

  .books & {
    /* book stuff */
  }

}

编译为:

.books article, .dvds article, .magazines article {
  /* book, dvd, magazine shared stuff */
}
.books article {
  /* book stuff */
}
于 2012-10-03T18:38:41.843 回答