SASS - 将集合传递给sass mixin作为参数

时间:2017-06-07 08:58:31

标签: collections sass mixins

如何将集合传递给sass mixin?

=media($type1, $size1: null)
  @if ($type1) and ($size1)
    @media ($type1: $size1)
      @content
  @elseif ($type1) and not ($size1)
    $collection: $type1
    @media (nth($collection, 1): nth($collection, 2)) <-- ERROR
      @content
  @else
    @error "Upsss...."

用例

$m: "36em"
$minw: "min-width
$tablet: ("type1": $minw, "size1": $m)

+media($tablet) <-- ERROR
  p
    font-size: 2em

1 个答案:

答案 0 :(得分:0)

排序。我不得不使用#{map-get($ collection,$ key-name)}函数

=media($type1, $size1: null)
  @if ($type1) and ($size1)
    @media ($type1: $size1)
      @content
  @elseif ($type1) and not ($size1)
    $collection: $type1
    @media (#{map-get($collection, "type1")}: #{map-get($collection, "size1")})
      @content
  @else
    @error "Upsss...."