【问题标题】:sass using variable as mixin datasass 使用变量作为 mixin 数据
【发布时间】:2014-04-01 18:06:49
【问题描述】:

我正在使用 csswizardry 中的网格并希望将断点创建为变量... 如果定义为标准“字符串”:

$breakpoints: (
    'palm' '(max-width: 480px)'
)!default;

但是当我把它改成:

$palmmaxwidth: 480px;
$breakpoints: (
    'palm' '(max-width: $palmmaxwidth)'
)!default;

它不会在 mixin 中正确编译:

@mixin grid-media-query($media-query){
    $breakpoint-found: false;

    @each $breakpoint in $breakpoints{
        $name: nth($breakpoint, 1);
        $declaration: nth($breakpoint, 2);

        @if $media-query == $name and $declaration{
            $breakpoint-found: true;

            @media only screen and #{$declaration}{
                @content;
            }
        }
    }

    @if $breakpoint-found == false{
        @warn "Breakpoint ‘#{$media-query}’ does not exist"
    }
}

错误是Invalid CSS after "...nd (max-width: ": expected expression (e.g. 1px, bold), was "$palmmaxwidth)"

我错过了什么?

【问题讨论】:

    标签: css sass mixins


    【解决方案1】:

    尝试所有可能的组合后,解决方案非常简单:

    $breakpoints: (
        'palm' '(max-width: '+$palmmaxwidth+')'
    )!default;
    

    【讨论】:

    • 你也可以使用字符串插值'(max-width: #{$palmmaxwidth})'代替串联
    猜你喜欢
    • 2014-09-22
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 2020-09-13
    • 2018-12-07
    • 1970-01-01
    • 2015-04-11
    相关资源
    最近更新 更多