找到你要的答案

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

Q:在SASS,如何借鉴父母两类符号与元素化合物?

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

For instance:

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

Produces:

a.one, .two {
  color: blue;
}

Rather than the intended:

a.one, a.two {
  color: blue;
}

Is there any way to get the intended result using a similar method?

使用这里找到的方法,它的工作原理,但不是两个父类。

例如:

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

生产:

a.one, .two {
  color: blue;
}

而不是预期的:

a.one, a.two {
  color: blue;
}

有没有办法用类似的方法得到预期的结果?

answer1: 回答1:

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.

你想用selector- append()函数代替:

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

利用插值的家长选择原因非它作为一个字符串评估(因为这是插值)。只有当你有一个选择器时,这才是可以接受的。选择添加(和所有其他选择*功能)将评估选择一列选择器添加您想要的项目,每一个选择列表中。

sass