In Sass, how to reference two parent classes with ampersand to compound with an element?

前端 未结 2 1906
渐次进展
渐次进展 2021-01-15 02:29

Using the method found here, it works, but not for two parent classes.

For instance:

.one, .two {
  @at-root a#{&} {
    color: blue;
  }
}
         


        
2条回答
  •  时光说笑
    2021-01-15 03:29

    You want to use the selector-append() function instead:

    .one, .two {
      @at-root #{selector-append(a, &)} {
        color: blue;
      }
    }
    

    Using interpolation on the parent selector causes Sass to evaluate it as a string (because that's what interpolation does). This only makes it acceptable to use when you have a single selector. The selector-append (and all other selector-* functions) will evaluate the selector as a list of selectors, appending your desired item to each selector in the list.

提交回复
热议问题