갈푸라떼
갈푸라떼는 개발중
갈푸라떼
전체 방문자
오늘
어제
  • 분류 전체보기 (232)
    • CS (0)
      • CSinfo (0)
    • Frontend (15)
      • HTML,CSS (1)
      • Javascript (2)
      • React (0)
      • React Hook (12)
    • Backend (0)
      • Python (0)
      • Node.js (0)
      • php (0)
    • DB (2)
      • MySQL (2)
      • BigQuery (0)
      • Mongodb (0)
    • Study (186)
      • JavaScript (72)
      • JavaScript(Clean code) (50)
      • Node.js (11)
      • HTML,CSS (13)
      • React (30)
      • TypeScript (10)
      • React-Native (0)
    • Error (2)
      • error (2)
    • Git (22)
      • Git (22)
    • Help Coding (4)
      • Useful websites (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • Github

공지사항

인기 글

태그

  • 컴파일러
  • nodemon
  • PM2
  • function
  • 정적 레벨
  • 인터프리터
  • symbol
  • 네이밍
  • 스코프 체인
  • class
  • this
  • structure
  • 자바스크립트엔진
  • 상속
  • 원시타입
  • 호이스팅
  • 이터러블
  • ECMAScript
  • Arrow
  • 실행 컨텍스트
  • 렉시컬 환경
  • SPREAD
  • 심볼
  • 싱글스레드
  • 오버라이딩
  • prototype
  • 프로토타입
  • 함수
  • Babel
  • 객체타입

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
갈푸라떼

갈푸라떼는 개발중

[CSS_study] display : grid_8 auto-fit & auto-fill
Study/HTML,CSS

[CSS_study] display : grid_8 auto-fit & auto-fill

2022. 5. 18. 00:32

* auto-fit & auto-fill

repeat() 함수 안에서만 동작한다.
이 둘을 이용하면 responsive website(반응형 웹사이트)를 손쉽게 만들 수 있다.


즉, 대부분의 경우 repeat()의 첫번째 인자로 직접 숫자를 쓰는 것보다 auto-fill, auto-fit
둘 중 하나를 쓰는 경우가 좋은 방법이다.

 

* auto-fit은 유동적인 사이즈를 위해서 사용되고 auto-fill은 정확한 사이즈를 위해 사용된다.

  • element들을 같은 사이즈로 맞추고싶다면 auto-fill
  • element들의 크기도 커졌으면 좋겠다면 auto-fit

(참고) auto-fill에 하나의 요소가 추가되면 빈공간에 할당된다.

(참고) auto-fit에 하나의 요소가 추가되면 row안에 맞추기 위해서 다른 element들의 사이즈가 조금 줄어든다.


* auto-flll

우리가 정해준 크기 안에서 가능한 한 많은 빈 column(row)를 만들어준다.
(남는 공간을 빈 cell로 가득 채움)

 

* auto-flll 예시 그림


* auto-fit

현재 element를 stretch해서 colum(row) 딱 맞게(fit) 해준다.
(남는 공간에 현재 요소를 stretch해서 가득 채움)


(참고) CSS를 연습할 때는 firefox 브라우저가 가장 좋다고 한다. Live Server는 가끔 CSS가 먹통이 될 수 있으니 CSS 연습할 때만은 사용을 지양하는 것이 좋은 것 같다

 

* auto-fit 예시 그림


* auto-fit & auto-fill 예시코드

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="test.css" />
  </head>
  <body>
    auto-fill
    <div class="grid">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
    </div>
    auto-fit
    <div class="grid">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
    </div>
  </body>
</html>

 

.grid {
  color: white;
  display: grid;
  gap: 5px;
  grid-auto-rows: 100px;
  margin-bottom: 30px;
}

.item:nth-child(odd) {
  background-color: #2ecc71;
}

.item:nth-child(even) {
  background-color: #3498db;
}

.grid:first-child {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}

.grid:last-child {
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

'Study > HTML,CSS' 카테고리의 다른 글

[CSS_study] display : grid_7 minmax & min-content & max-content  (0) 2022.05.18
[CSS_study] display : grid_6 place-self & auto columns and rows  (0) 2022.05.17
[CSS_study] display : grid_5 place-items & place-content  (0) 2022.05.17
[CSS_study] display : grid_4 grid-template & fr (fraction)  (0) 2022.05.17
[CSS_study] display : grid_3 (Line Naming)  (0) 2022.05.14
    'Study/HTML,CSS' 카테고리의 다른 글
    • [CSS_study] display : grid_7 minmax & min-content & max-content
    • [CSS_study] display : grid_6 place-self & auto columns and rows
    • [CSS_study] display : grid_5 place-items & place-content
    • [CSS_study] display : grid_4 grid-template & fr (fraction)
    갈푸라떼
    갈푸라떼

    티스토리툴바