728x90
반응형

List는 하나의 변수에 여러값을 담을수 있다.

each문으로 출력한다.

@mixin List_Test($property, $value) {
    $prefixes: webkit, moz, ms, o;
    @each $prefix in $prefixes {
        #{'-' + $prefix + '-' + $property}: $value;
    }
    // 기본
    #{$property}: $value;
}

Map 은 key와 value 가 세트다. json 형태로 생각하면 된다.

$Map_test :(
    "인사":"hello",
    color:#000,
    "margin":"20px"
);
@each $name, $val in $Map_test {
    .map_test {
      #{$name} : $val; 
    }
}

scss -> css 빌드

.map_test {
  인사: "hello";
}
.map_test {
  color: #000;
}
.map_test {
  margin: "20px";
}

MAP 2개 이상 사용시

기본은 기본값이 있고, 그외의 값 사용시 따른값 출력한다

$Map_test :(
    first : (
        "인사":"hello",
        color:#000,
        "구매":"레몬"
    ),
    second:(
        "인사":"안녕",
        color:red,
        "구매":"딸기"
    )
);

@function mapFunc($key,$type:"first"){
    @each $name, $val in map-get($Map_test,$type){
      @if($key == $name){
        @return $val;
      }
    }
}

@mixin map-test($property,$type){
    #{$property}: mapFunc($type);
    @at-root body & .abc .edf & &{ // & 는 
        #{$property}: mapFunc($type,second);
    }
}

.MAP_TEST{
    @include map-test(color,"구매")
}
728x90
반응형

'front-end > CSS & SCSS' 카테고리의 다른 글

vue3 vite css sourcemap 설정  (0) 2023.06.13
@at-root 의 사용법  (0) 2023.06.13
여러개의 모드(다크,민트등) SCSS 제작 방식  (0) 2023.06.13
flex or grid  (0) 2023.06.13
sticky vs fixed  (0) 2023.06.13

+ Recent posts