【问题标题】:Conditional in SASS mixin throws errorSASS mixin 中的条件抛出错误
【发布时间】:2015-01-22 12:16:39
【问题描述】:

我正在尝试使用条件创建一个 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 的第一行),然后另外在条件中将该变量/参数的值放在引号中测试。在每种情况下,我都会遇到相同的错误。看了很多条件 mixins 的例子后,我仍然看不出我的语法哪里错了。

【问题讨论】:

    标签: sass mixins


    【解决方案1】:

    你的 mixin 没有错,只是你说错了。 Sass 知道 CSS 属性不允许在选择器之外。

    不正确:

    @include mypadder;
    

    正确:

    .foo {
        @include mypadder;
    }
    

    【讨论】:

    • 啊!我怎么错过了?几天来我一直在不停地放置@includes,所以我什至不能辩解“我不知道如何使用mixins”。你知道你是怎么看不到树木的……很高兴知道我的基本混合是正确的。干杯。
    猜你喜欢
    • 2022-08-24
    • 2020-08-15
    • 2015-06-17
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2018-01-17
    • 2014-06-06
    • 1970-01-01
    相关资源
    最近更新 更多