【问题标题】:Isolate nested sass map into new map将嵌套的 sass 地图隔离到新地图中
【发布时间】:2017-11-09 13:36:46
【问题描述】:

如何将嵌套的 sass 地图隔离到新地图中?例如,我有这样的 sass 地图:

$susy-setting: (
  s: (
    'columns': 4,
    'gutters': 30px,
  ),

  m: (
    'columns': 8,
    'gutters': 30px,
  ),

  l: (
    'columns': 12,
    'gutters': 30px,
  )
);

然后我需要在循环之后隔离每个映射,因为我的其他 mixin 需要映射作为它的参数。

@each $setting in $susy-setting{
    @include susy-settings-block($setting) { // This mixin need map
        @for $i from 1 through map-get($setting, 'columns') {
            @content;
        }
    }
}

【问题讨论】:

    标签: sass susy sass-maps


    【解决方案1】:

    要回答您的主要问题,您需要获取循环中的键和值:@each $size, $setting in $susy-setting$size 变量将存储键(例如sml),而$setting 变量存储分配给该键的映射值。

    编辑:我看到了您对我的要点的评论,这提供了更多背景信息。试试这个:

    @mixin susy-settings-block(
      $name, 
      $config: $susy-settings
    ) {
      // store the old settings
      $global: $susy;
    
      // Get the new settings by name
      $new: map-get($config, $name);
    
      // apply the new settings
      $susy: map-merge($susy, $new) !global;
    
      // allow nested styles, using new settings
      @content;
    
      // return to the initial settings
      $susy: $global !global;
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 2020-04-22
    相关资源
    最近更新 更多