我正在尝试编写一个混合程序,它将在输出时修改父选择器。这样做的想法是,在调用混音的情况下,父选择器需要对其进行字符串替换。我有大部分的工作,但我不知道如何吞下&。
.test {
@include alt_parent() {
content: 'test';
}
}混合器是这样的:
@mixin alt_parent() {
#{str-replace(unquote("#{selector_append(&)}"), "s", "x")} {
@content;
}
}我的字符串替换工作,所以这不是问题。我得到的是这个(我明白为什么):
.test .text {
content: 'test';
}我想要的是:
.text {
content: 'test';
}发布于 2017-05-10 17:44:02
您必须使用@at-root指令来避免自动包含由&表示的选择器。
http://alwaystwisted.com/articles/2014-03-08-using-sass-33s-at-root-for-piece-of-mind
@mixin alt_parent($parent) {
@at-root {
#{str-replace(unquote("#{selector_append(&)}"), "s", "x")} {
@content;
}
}
}https://stackoverflow.com/questions/43899068
复制相似问题