【问题标题】:SCSS complex/nested mapSCSS 复杂/嵌套映射
【发布时间】:2019-06-13 12:29:11
【问题描述】:

我想从嵌套映射中生成一些 CSS 代码,但我可以访问参数和值。我已经把地图贴在这里了。我想上不同的课。它们应该是这样的。

.is-fluid {
 width: 100%;
 height: auto;
 border-radius: 0;
}

等等……

我尝试了不同的方法,但无法运行。 这甚至可能吗?怎么做?

$images: (
    styles: (
        fluid: (
            'width': 100%,
            'height': auto,
            'border-radius': 0
        ),
        rounded: (
            'width': auto,
            'height': auto,
            'border-radius': .5rem
        ),
        circled: (
            'width': auto,
            'height': auto,
            'border-radius': 50%
        )
    )
)

【问题讨论】:

    标签: sass


    【解决方案1】:

    Sass maps.

    $images: (
        styles: (
            fluid: (
                'width': 100%,
                'height': auto,
                'border-radius': 0
            ),
            rounded: (
                'width': auto,
                'height': auto,
                'border-radius': .5rem
            ),
            circled: (
                'width': auto,
                'height': auto,
                'border-radius': 50%
            )
        )
    );
    
    @each $style-name, $style-content in map-get($images, 'styles') {
      .is-#{$style-name} {
        @each $key, $value in $style-content {
            #{$key}: #{$value}; 
        }
      }
    }
    

    编译为:

    .is-fluid {
      width: 100%;
      height: auto;
      border-radius: 0;
    }
    
    .is-rounded {
      width: auto;
      height: auto;
      border-radius: 0.5rem;
    }
    
    .is-circled {
      width: auto;
      height: auto;
      border-radius: 50%;
    }
    

    【讨论】:

    • 不错!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    • 2015-11-23
    相关资源
    最近更新 更多