在每个 mixin 中使用变量数组

Use an array of variables in an each mixin

我很难弄清楚如何为要在“每个”语句中使用的变量编写数组。

        $array: (("1", "../../Media/Images/FirstImage.png"), ("2", "../../Media/Images/SecondImage.png"));

        @each $i in $array {
          &:nth-child( #{$i} ) {
            a {
              &:before {
                content: "";
                background: url({This is the 2nd part of each variable}) no-repeat;
              }
            }
          }
        }

您当前有一个数组数组,而不是一个 single-dimensional 变量或值数组。似乎您可以将数组更改为一维,并且只需使用 :nth-child().

的索引
$urls: ("../../Media/Images/FirstImage.png", "../../Media/Images/SecondImage.png");


@each $url in $urls {
  $i: index($urls, $url);
  &:nth-child(#{$i}) {
    a {
      &:before {
        content: "";
        background: url($url) no-repeat;
      }
    }
  }
}