Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我以 BEM 样式编写 CSS 并拥有以下代码:
.nav { &__list { &__item { } } &__link { &--active { } } }
我如何从上面的代码中获取.nav .nav__link--active和获取.nav__link.nav__link--active?我怎样才能通过这种方法提高特异性?
.nav .nav__link--active
.nav__link.nav__link--active
There is no magic method for this. Store the desired selector as a variable and nest like normal.
.nav { $sel: &; &__list { &__item { color: red; #{$sel} & { border: 1px solid; } } } &__link { &--active { color: blue; #{$sel} & { border: 1px dashed; } } } }