【问题标题】:SASS - Passing collection to sass mixin as an argumentSASS - 将集合作为参数传递给 sass mixin
【发布时间】:2023-03-20 02:40:02
【问题描述】:

如何将集合传递给 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

【问题讨论】:

    标签: collections sass mixins


    【解决方案1】:

    已排序。我不得不使用 #{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...."
    

    【讨论】:

      猜你喜欢
      • 2013-01-05
      • 2020-06-13
      • 2016-12-15
      • 2011-11-22
      • 2015-05-07
      • 2018-12-30
      • 2021-06-11
      • 2012-12-24
      • 2014-02-20
      相关资源
      最近更新 更多