SASS - 通过项目索引获取地图项目值 [英] SASS - get map item value by item index

查看:34
本文介绍了SASS - 通过项目索引获取地图项目值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过该地图项的索引选择一个 SASS 地图项值.
简化场景:

I want to be able to pick a SASS map item value by that map item's index.
Simplified scenario:

// Colors map (MUST stay this way due to system dependence)
$colors: (
    a: red,
    b: green,
    c: blue
);

@for $i from 1 through 3{
    a:nth-child({$i}){ color:[GET COLOR BY $i FROM $COLORS]; }
}

这可能吗?

推荐答案

gist demo>

$colors: (
    a: red,
    b: green,
    c: blue
);

@each $color, $name in $colors{
  $i: index($colors, $color $name);
  a:nth-child(#{$i}){ color:$color; }
}

这篇关于SASS - 通过项目索引获取地图项目值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆