gpt4 book ai didi

SASS Mixin 重写 & (&)

转载 作者:行者123 更新时间:2023-12-04 20:32:11 29 4
gpt4 key购买 nike

我正在尝试编写一个 mixin 来修改输出的父选择器。这个想法是,在调用 mixin 的情况下,父选择器需要对其进行字符串替换。我有大部分工作,但我不知道如何吞下 & .

.test {
@include alt_parent() {
content: 'test';
}
}

mixin 是这样的:
@mixin alt_parent() {
#{str-replace(unquote("#{selector_append(&)}"), "s", "x")} {
@content;
}
}

我有字符串替换工作,所以这不是问题。我得到的是这个(我明白为什么):
.test .text {
content: 'test';
}

我想要的是这个:
.text {
content: 'test';
}

最佳答案

您必须使用 @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;
}
}
}

关于SASS Mixin 重写 & (&),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43899068/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com