【问题标题】:How to inject literal string into scss @mixin如何将文字字符串注入 scss @mixin
【发布时间】:2019-02-20 08:43:49
【问题描述】:

考虑以下 scss 代码:

@mixin homeSlider(
    $dim: 150px,
    $h1: "h1 { font-size: 4em; margin-top: 0; }"
){
    section {
        margin-top: -$dim;
    }
    $h1;
 }

 @include homeSlider( $dim: 50px, $h1: "h1 { font-size: 3em; margin-top: 0; }" )

我需要知道如何实现我的目标

【问题讨论】:

    标签: css sass scss-mixins


    【解决方案1】:

    试试这个

    @mixin homeSlider($dim, $h1-font-size){
        section {
            margin-top: -$dim;
    
            h1 {
               font-size: $h1-font-size;
               margin-top: 0;
            }
        }
    }
    
    
    @include homeSlider(50px, 3em;)  /* $dim = 50px - $h1-font-size = 3em; */
    

    【讨论】:

    • 相当不错,但如果我们有多个参数,这可能很快就会变得冗长。我在想一种捷径。
    • 不确定我是否理解,但如果您想要更多参数/参数,我建议您查看this link
    猜你喜欢
    • 2013-11-25
    • 2021-08-03
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 2017-04-24
    • 2018-10-25
    相关资源
    最近更新 更多