@euid/scss-mixins
  • Sass 믹스인 라이브러리
  • Getting Started
    • 시작하기
    • 환경 구성
    • 변경 이력
    • VS Code 확장
  • Utilities
    • 단위 (Unit)
      • rem()
      • em()
      • unitless-px()
      • remove-unit()
      • get-number-or-string()
    • 컬러 (Color)
      • get-color()
      • get-color-name()
      • has-color()
      • alt-color()
      • a11y-color()
      • light-or-dark()
      • color-contrast()
      • most-legible-color()
    • 문자 (String)
      • str-replace()
      • str-split()
      • str-to-num()
      • str-repeat()
      • str-extract-count-keyword()
    • 리스트 (List)
      • first()
      • last()
      • copy-list()
      • merge-list()
      • get-value-after-key()
      • get-match-value-of-keys()
    • 검사 (Validation)
      • is-valid-types()
      • is-valid-keywords()
      • is-include-items()
    • 이징 (Easing)
      • ease()
      • ease-add()
      • ease-merge()
  • Mixins
    • 폰트 (Font)
      • font()
      • font-face()
      • font-size-padding()
    • 텍스트 (Text)
      • text()
      • text-ellipsis()
    • 간격 (Spacing)
      • margin()
      • m()
      • mx()
      • my()
      • padding()
      • p()
      • px()
      • py()
      • space()
      • s()
      • sx()
      • sy()
    • 디스플레이 (Display)
      • show()
      • hide()
      • order()
    • 포지션 (Position)
      • position()
      • relative()
      • absolute()
      • fixed()
      • sticky()
      • static()
    • 플렉스박스 (Flexbox)
      • Flex 컨테이너(Container)
        • flex-container()
        • flex-container-append()
      • Flex 아이템(Item)
        • flex-item()
        • flex()
    • CSS 그리드 (Grid)
      • Grid 컨테이너(Container)
        • grid-container()
        • grid-container-append()
          • grid-rows()
          • grid-cols()
          • grid-auto()
            • auto-rows()
            • auto-cols()
            • auto-flow()
          • grid-areas()
          • gap()
      • Grid 아이템(Item)
        • grid-item()
        • grid-area()
        • grid-row()
          • row-start()
          • row-end()
          • row-span()
        • grid-col()
          • col-start()
          • col-end()
          • col-span()
    • 박스 정렬 (Box Alignment)
      • box-alignment()
      • place()
        • content()
        • items()
        • self()
      • justify-content()
      • align-content()
      • justify-items()
      • align-items()
      • justify-self()
      • align-self()
    • 반응형 웹 (Rsponsive Web)
      • media()
      • rwd-img()
      • rwd-video()
      • rwd-iframe-wrapper()
    • 이니셜라이즈 (Initialize)
      • initialize()
      • normalize()
      • reset-box()
      • reset-box-sizing()
      • reset-img()
      • reset-link()
      • reset-list()
      • reset-dl()
      • reset-abbr()
      • reset-button()
    • 인터페이스 (Interface)
      • appearance()
      • selection()
      • scrollbar()
    • 접근성 (Accessibility)
      • a11y-hidden()
      • focus-visible()
    • 상속 (Inheritance)
      • inherit-box-sizing()
      • inherit-pseudo-elements()
    • 폼 (Form)
      • button()
      • input()
      • radio()
      • search()
      • checkbox()
      • placeholder()
      • textarea()
      • select()
      • select-multiple()
Powered by GitBook
On this page
  • 용도
  • 사용법
  • 로직
  • 참고

Was this helpful?

  1. Mixins
  2. 폰트 (Font)

font-size-padding()

글자 크기(font-size) 기준 패딩(padding) 설정 믹스인

용도

글자 크기(rem 단위)를 기준으로 패딩(em 단위)을 설정해야 할 때, 편리하게 활용하기 위한 믹스인입니다.

사용법

font-size-padding() 믹스인에 글자 크기와 패딩 값을 px 단위로 전달합니다. (단위 생략 가능)

font-size-padding($font-size:number, $padding:[number, string, list])

.usage {
  @include font-size-padding(20, 10 16 8);
}

매개변수(parameter)

유형(type)

필수(required)

기본 값(default)

$font-size

number

✔︎

$padding

number, string, list

✔︎

위 예시 코드는 아래의 CSS로 컴파일 되어 출력됩니다.

.usage {
  padding: 0.5em 0.8em 0.4em;
  font-size: 1.25rem;
}

font-size-padding() 믹스인 이름이 긴 경우, fsp() 별칭(단축 이름) 믹스인을 활용할 수도 있습니다.

.usage {
  @include fsp(20, 10 16 8);
}

로직

font-face() 믹스인은 다음의 로직에 의해 작성되었습니다.

@mixin font-size-padding($font-size, $padding) {
  // 전달 받은 $padding 유형 검사
  $type-collection: list number string;

  // 개발자가 요구하는 데이터 유형이 올바르게 전달된 경우 → 처리
  @if is-valid-types($padding, $type-collection) {
    $padding-type: type-of($padding);
    // 숫자인 경우
    @if $padding-type == 'number' {
      padding: em($padding, $font-size);
    }

    // 문자인 경우
    @if $padding-type == 'string' {
      padding: $padding;
    }

    // 리스트인 경우
    @if $padding-type == 'list' {
      // 새롭게 반환할 리스트 정의
      $convert-padding-list: ();

      @each $value in $padding {
        // 값이 숫자인 경우 (예: 10px)
        @if type-of($value) == 'number' {
          $convert-padding-list: append($convert-padding-list, em($value, $font-size));
        }

        // 값이 문자인 경우 (예: auto)
        @if type-of($value) == 'string' {
          $convert-padding-list: append($convert-padding-list, $value);
        }
      }

      padding: $convert-padding-list;
    }
  }
  // 개발자가 요구하지 않은 데이터 유형이 전달된 경우 → 오류 표시
  @else {
    @error '전달 받은 #{$padding} 값은 요구되는 #{join($type-collection, [], $separator: comma, $bracketed: true)} 유형이 아닙니다.';
  }

  // ----------------------------------------------

  // $font-size 전달 인자: 유효성 검사(validation)
  @if type-of($font-size) != 'number' {
    @error '전달 받은 #{$font-size} 값은 숫자 유형이 아닙니다.';
  }
  // $font-size 값을 설정
  font-size: rem($font-size);
}
  1. 전달 받은 글자 크기, 패딩 값을 계산하여 처리

  2. 패딩 간격은 글자 크기를 기준으로 em 단위로 환산하여 설정 (숫자 값이 아닌 문자 값은 그대로 설정)

fsp() 믹스인은 font-size-padding() 믹스인 래퍼로 보다 간단하게 쓰기 위해 작성되었습니다.

@mixin fsp($font-size, $padding) {
  @include font-size-padding($font-size, $padding);
}

참고

믹스인에 사용된 Sass의 빌트인 모듈은 다음과 같습니다.

믹스인에 사용된 자체 제작한 모듈은 다음과 같습니다.

Previousfont-face()Next텍스트 (Text)

Last updated 4 years ago

Was this helpful?

글자 크기는 rem 단위로 환산하여 설정 ( 기준 값으로 계산)

@mixin / @include
@if / @else
@error
type-of()
append()
is-valid-types()
rem()
em()
$base-rem-size