• 티스토리 홈
  • 프로필사진
    루루개발자
  • 방명록
  • 공지사항
  • 태그
  • 블로그 관리
  • 글 작성
루루개발자
  • 프로필사진
    루루개발자
    • 분류 전체보기 (213)
      • react & next.js (13)
      • Node.js & Javascript & Type.. (24)
        • d3.js (10)
      • 차트 만들기 (1)
      • 티스토리 스킨 개발 (7)
      • 내가 만든 패키지 (3)
      • 내가 만든 CSS (1)
      • CSS (7)
      • 도커 & 쿠버네티스 (3)
      • 개인 프로젝트 (7)
      • 리뷰 & 추천 (2)
      • 알고리즘 (1)
      • IT 기타 (18)
      • 잡동사니 (1)
      • Spring Boot (5)
      • 취미로 그리는 그림들 (120)
      • 개인적인 생각들 (0)
  • 반응형
  • 방문자 수
    • 전체:
    • 오늘:
    • 어제:
  • 최근 댓글
      등록된 댓글이 없습니다.
    • 최근 공지
        등록된 공지가 없습니다.
      # Home
      # 공지사항
      #
      # 태그
      # 검색결과
      # 방명록
      • utility class (유틸리티 클래스)
        2024년 01월 25일
        • 루루개발자
        • 작성자
        • 2024.01.25.:06
        반응형

        [ utility class 란? ]

        각각의 클래스들을 정적으로 하나 하나씩 작성하는 것이 아니라, 하나의 코드로 여러 클래스들을 동적으로 생성하는 방식을 유틸리티 클래스라고 할 수 있습니다. CSS 프레임워크인 TailwindCSS 가 이러한 유틸리티 클래스 방식을 사용하고 있는 대표적인 사례라고 할 수 있습니다.

         

        [ 예시 ]

        1. 다음과 같이 scss 파일을 작성합니다.

        -- index.scss

        $alignments: (
          "center", 
          "space-between", 
          "space-around", 
          "space-evenly", 
          "flex-start", 
          "flex-end"
        );
        
        @each $align in $alignments {
          .justify-#{$align} {
            justify-content: #{$align};
          }
        
          .items-#{$align} {
            align-items: #{$align};
          }
        
          .justify-items-#{$align} {
            justify-items: #{$align};
          }
        
          .content-#{$align} {
            align-content: #{$align};
          }
        }

        2. sass 를 전역으로 설치합니다. (이미 설치 되어 있다면 생략)

        npm i -g sass

        3. 아래 명령어를 통해 위에서 작성한 index.scss 를 index.css 로 트랜스파일합니다.

        sass ./index.scss ./index.css

        4. index.css 를 확인하면 아래와 같이 출력된 것을 확인 할 수 있습니다.

        -- index.css

        .justify-center {
          justify-content: center;
        }
        
        .items-center {
          align-items: center;
        }
        
        .justify-items-center {
          justify-items: center;
        }
        
        .content-center {
          align-content: center;
        }
        
        .justify-space-between {
          justify-content: space-between;
        }
        
        .items-space-between {
          align-items: space-between;
        }
        
        .justify-items-space-between {
          justify-items: space-between;
        }
        
        .content-space-between {
          align-content: space-between;
        }
        
        .justify-space-around {
          justify-content: space-around;
        }
        
        .items-space-around {
          align-items: space-around;
        }
        
        .justify-items-space-around {
          justify-items: space-around;
        }
        
        .content-space-around {
          align-content: space-around;
        }
        
        .justify-space-evenly {
          justify-content: space-evenly;
        }
        
        .items-space-evenly {
          align-items: space-evenly;
        }
        
        .justify-items-space-evenly {
          justify-items: space-evenly;
        }
        
        .content-space-evenly {
          align-content: space-evenly;
        }
        
        .justify-flex-start {
          justify-content: flex-start;
        }
        
        .items-flex-start {
          align-items: flex-start;
        }
        
        .justify-items-flex-start {
          justify-items: flex-start;
        }
        
        .content-flex-start {
          align-content: flex-start;
        }
        
        .justify-flex-end {
          justify-content: flex-end;
        }
        
        .items-flex-end {
          align-items: flex-end;
        }
        
        .justify-items-flex-end {
          justify-items: flex-end;
        }
        
        .content-flex-end {
          align-content: flex-end;
        }

         

        [ 참고자료 ]

        https://dev.to/ahmedsarhan/how-to-build-your-own-utility-framework-using-scss-25dh

         

        How to build your own Utility classes using plain Scss alone

        In this article, we will talk and code about using couple of the amazing Sass features to give us som...

        dev.to

         

        [ 대표 이미지 출처 ]

        https://en.m.wikipedia.org/wiki/File:Sass_Logo_Color.svg

         

        File:Sass Logo Color.svg - Wikipedia

        Original file ‎(SVG file, nominally 512 × 384 pixels, file size: 4 KB) Summary Licensing Public domainPublic domainfalsefalse This work includes material that may be protected as a trademark in some jurisdictions. If you want to use it, you have to ensu

        en.m.wikipedia.org

         

        반응형

        'CSS' 카테고리의 다른 글

        CSS 가 적용되는 우선순위  (0) 2024.01.24
        CSS 에서 사용하는 길이 단위  (0) 2022.10.02
        ul, ol 태그에서 커스텀 마커 사용하는 방법  (1) 2022.07.05
        bell shake 애니메이션 예제  (0) 2022.05.12
        infinity rotate 애니메이션 예제  (0) 2022.05.11
        다음글
        다음 글이 없습니다.
        이전글
        이전 글이 없습니다.
        댓글
      조회된 결과가 없습니다.
      스킨 업데이트 안내
      현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
      ("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)
      목차
      표시할 목차가 없습니다.
        • 안녕하세요
        • 감사해요
        • 잘있어요

        티스토리툴바