css - 具有多个属性的 SCSS rem mixin

标签 css sass

我目前正在使用 REM mixin由卡尔默克利。

它工作得很好,但是我发现我在这个过程中写了很多@includes。例如:

    @include rems(height, 1);
    @include rems(width, 1);
    @include rems(margin, 1, 0, 4, 0);
    @include rems(padding, 0.5, 1);
    // plus all other @includes Ii might use too
    @include opacity(0.7);
    @include clearfix;
    // etc

我正在尝试找出一种方法,将对同一个 mixin 的引用合并为一个。最终我正在寻找一个解决方案,我可以在其中编写类似于以下内容的内容:

    @include rems(height, 1; width, 1; margin, 1, 0, 4, 0; padding, 0.5, 1;);

提前致谢

最佳答案

一个解决方案是创建一个中间混入,它接受一个列表列表并将每个列表交给 rems 混入:

@mixin multi-rems($lists) {
    @each $list in $lists {
        @include rems($list...);
    }
}

然后像这样使用它:

li {
    @include multi-rems(((margin, 0, 4), (padding, 2, 3)));
}

这是一个 SassMeister Gist .干杯。

关于css - 具有多个属性的 SCSS rem mixin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38591351/

相关文章:

html - 如何将水平条转换为响应式?

python - 使用 CSS 媒体查询和 Flask/Jinja 进行设备检测

html - 在 ionic 元素中设置 SASS

ruby-on-rails - Rails/Sass : Import file from the vendor folder

css - 如何在AngularDart元素中将div图像与中心对齐?

html - 为什么我的 css 没有应用?

html - 输入框移动到下一行

html - DIV 宽度 : auto is 0 pixel

css - 使用 SASS 和 OOCSS 引用

css - 在 SASS/Compass 输出前添加注释