首页 > 解决方案 > 如何将文字字符串注入 scss @mixin

问题描述

考虑以下 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; }" )

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

标签: csssassscss-mixins

解决方案


尝试这个

@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; */

推荐阅读