作者:书友50398197 | 来源:互联网 | 2023-05-25 15:37
我正在尝试使用条件创建一个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的第一行)中的位置,然后在条件测试中另外在该变量/参数的值周围加上引号.在每种情况下,我都会得到同样的错误.看了很多条件混合的例子后,我仍然无法看到我的语法错误.
1> cimmanon..:
你的mixin没什么问题,你只是说错了.Sass知道在选择器之外不允许使用CSS属性.
不正确:
@include mypadder;
正确:
.foo {
@include mypadder;
}