SASS mixin中的条件抛出错误

时间:2015-01-22 12:16:39

标签: sass mixins

我尝试使用条件创建一个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 个答案:

答案 0 :(得分:11)

你的mixin没什么问题,你只是说错了。 Sass知道在选择器之外不允许使用CSS属性。

不正确:

@include mypadder;

正确:

.foo {
    @include mypadder;
}