gpt4 book ai didi

sass - SASS mixin 中的条件抛出错误

转载 作者:行者123 更新时间:2023-12-02 19:34:58 25 4
gpt4 key购买 nike

我正在尝试使用条件创建一个 mixin,但在编译时出现错误。生成的错误是:

Error: Properties are only allowed within rules, directives, mixin includes, or other properties.

这是我正在使用的代码:

@mixin mypadder ($topBottomBoth: myDefaultOption, $topUnits: 0, $bottomUnits: 0) {
@if $topBottomBoth == tp {
padding-top: 1em;
}
@else if $topBottomBoth == bt {
padding-bottom: 1em;
}
@else {
padding-top: 1em;
padding-bottom: 1em;
}
}

我还尝试将 $topBottomBoth 参数的值放在引号中,首先是它出现在参数中的位置(mixin 的第一行),然后另外在条件条件中将该变量/参数的值放在引号中测试。在每种情况下我都会遇到相同的错误。在查看了许多条件混入的示例之后,我仍然看不出我的语法错误在哪里。

最佳答案

你的 mixin 没有任何问题,你只是调用错误了。 Sass 知道 CSS 属性不允许出现在选择器之外。

错误:

@include mypadder;

正确:

.foo {
@include mypadder;
}

关于sass - SASS mixin 中的条件抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28088550/

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