SASS/SCSS object key value loop [duplicate]

拥有回忆 提交于 2019-12-04 01:03:54

Sass does not currently support mappings. You'll have to live with lists of lists for now.

$icons: star "\2605", lightning "\26A1";

@each $icon in $icons {
  $key: nth($icon, 1);
  $value: nth($icon, 2);

  .icon-#{$key} {
    @extend .icon;

    &:after {
      content: $value;
    }
  }
}

Sass 3.3 (released on 2014/03/07) now allows you to use maps :

@include font-face('Entypo', font-files('entypo.woff'));

.icon {
  display: inline;
  font: 400 40px/40px Entypo;
}

$icons: (
  star: "\2605",
  lightning: "\26A1"
);

@each $key, $value in $icons {
  .icon-#{$key} {
    @extend .icon;

    &:after {
      content: $value;
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!