티스토리 뷰

WEB/CSS

CSS Grid Container 속성

찐망고 2024. 2. 2. 16:49
728x90
반응형

 

 

CSS Grid Layout-1

안녕하세요 찐망고입니다. 오늘은 그리드 레이아웃에 대해 포스팅을 해볼 건데요. 저는 음 실무에 그나마 더 도움이 될만한 각각의 섹션을 그리드로 짜볼까 하는데요. 수업 중에는 하나의 섹션

uiweb.tistory.com

 

 

CSS Grid Layout-2

안녕하세요 찐망고입니다. 오늘도 그리드 레이아웃을 이용한 포스팅을 해볼 건데요. 일단 grid에 관련된 이전글 하나 보시고 2023.12.29 - [WEB/CSS] - CSS Grid Layout-1 CSS Grid Layout-1 안녕하세요 찐망고입

uiweb.tistory.com

 

 

안녕하세요 찐망고입니다.

이전에 그리드 레이아웃에 대한 포스팅을 올렸는데요.

 

오늘은 그리드컨테이너 속성만 따로 정리하는 포스팅입니다 ㅎ

 

display 속성

/* 블록 형태의 그리드 적용 */
.grid-container {
	display: grid;
}

/* 인라인블록 형태의 그리드 적용 */
.grid-container {
	display: inline-grid;
}

 

 

Grid Container 속성

Grid Container 속성
grid-template-rows 그리드 레이아웃의 행 크기를 지정
grid-template-columns 그리드 레이아웃의 열 크기를 지정
grid-template-areas 이름을 직접 지어  grid items와 연결할 틀을 만듬
grid-template grid-template 축약 속성
row-gap 그리드 행과 행사이의 간격
column-gap 그리드 열과 열사이의 간격
gap gap 축약 속성
grid-auto-rows 기본적인 행 크기 지정
grid-auto-columns 기본적인 열 크기 지정
grid-auto-flow 자동 배치된 항목이 그리드에 삽입되는 방법을 지정
grid grid-template속성과 grid-auto속성의 축약 속성
align-content 컨테이너 내부의 전체 그리드를 수직으로 정렬하는 데 사용
justify-content 컨테이너 내부의 전체 그리드를 수평 정렬하는 데 사용
place-content align-content와 justify-content의 단축 속성
align-items 그리드 아이템을 수직으로 정렬하는 데 사용
justify-items 그리드 아이템을 수평 정렬하는 데 사용
place-items align-items와 justify-items의 단축 속성

 

 

1. grid-template-rows / grid-template-columns

 - 각 행과 열을 나누는 속성으로 수치를 준 만큼 행과 열이 생성됩니다.

 - 반복되는 행과 열은 repeat()을 사용할 수 있습니다.

 - auto는 컨텐츠 크기, 1fr은 남는 여백을 n분의1한다고 생각하면 됩니다.

 - 함수는 두번째 인수를 반복할 수 있으므로 마지막 코드처럼 표기할 수 있습니다.

/* grid-template-rows: none|auto|max-content|min-content|length|initial|inherit; */

/* grid-template-columns: none|auto|max-content|min-content|length|initial|inherit; */

.grid-container {
    display: grid;
    grid-template-columns: 200px 100px auto 100px;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
}

.grid-container {
   display: grid;
   grid-template-columns: repeat(4, 1fr 2fr);
   /* 1fr, 2fr, 1fr, 2fr, 1fr, 2fr, 1fr, 2fr */
}

 

 

2. grid-template-areas

- 그리드 컨테이너와 그리드 아이템의 이름이 서로 같아야 합니다.

- grid layout1 게시글을 참고해주세요.

- 마침표를 사용하여 빈 영역을 지정할 수 있습니다.

.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    ". item01 ."
    "item02 . item03";
}
.item01 {
	grid-areas: item01;
}
.item02 {
	grid-areas: item02;
}
.item03 {
	grid-areas: item03;
}

 

 

3. grid-template

/* grid-template: <grid-template-rows> / <grid-template-columns>; */
/* grid-template: <grid-template-areas>; */


.grid-container {
  grid-template: 150px / auto auto auto;  
}

.grid-container {
    grid-template: 
        ". item01 ." 100px
        "item02 . item03" 200px
        / 1fr auto 100px;
}

/* 위 속성을 풀어 써보면 */
.grid-container {
    grid-template-rows: 100px 200px;
    grid-template-columns: 1fr auto 100px;
    grid-template-areas:
        ". item01 ."
        "item02 . item03";
}

 

 

 

4. row-gap / column-gap / gap

 - 열과 행으로 이루어진 그리드요소들 사이의 간격을 지정

/* gap: <row-gap> <column-gap>; */
.grid-container {
    display: grid;
    grid-template-colums: repeat(2, 1fr);
    gap: 10px 20px;
}

 

 

5. grid-auto-rows / grid-auto-columns

-  grid-template-row와 grid-template-colimns와 마찬가지로 행과 열 크기를 설정하지만

크기가 설정되지 않는 그리드 아이템에만 적용

 - 미디어 쿼리 시 열의 갯수가 달라지는 경우 지정해 놓음 편할 듯 

 

6. grid-auto-flow

- 자동 배치된 항목이 그리드에 삽입되는 방식을 제어

 - https://www.w3schools.com/cssref/playdemo.php?filename=playcss_grid-auto-flow

 

W3Schools CSS grid-auto-flow demonstration

.grid-container grid-auto-flow row| column| dense| row dense| column dense Demo of the different values of the grid-auto-flow property.

www.w3schools.com

grid-auto-rows: auto|max-content|min-content|length; 

row: 각 행 축에 따라 차례로 배치됨
columns: 각 열 축에 따라 차례로 배치됨
row dense: 각 행 축에 따라 차례로 배치됨, 빈 영역을 채움
columns dense: 각 열 축에 따라 차례로 배치됨, 빈 영역을 채움

grid-auto-flow row와 row dense비교
grid-auto-flow column과 column dense 둘이 같다

 

 

 

 

7. Grid

.grid-container {
    display: grid;
    grid: none;
}
.grid-container {
    display: grid;
    grid: grid-template-rows / grid-template-columns;
}
.grid-container {
    display: grid;
    grid: grid-template-areas;
}
.grid-container {
    display: grid;
    grid: grid-template-rows / [grid-auto-flow] grid-auto-columns;
}
.grid-container {
    display: grid;
    grid: [grid-auto-flow] grid-auto-rows / grid-template-columns
}

 

 

8. justify-content

- Normal 기본값 (Stretch와 같음)

- flex속성의 가로 주축을 기준으로 정렬하여 배치하는 방법과 같음

.grid-container {
  display: grid;
  justify-content: normal;
}
.grid-container {
  display: grid;
  justify-content: space-evenly;
}
.grid-container {
  display: grid;
  justify-content: space-around;
}
.grid-container {
  display: grid;
  justify-content: space-between;
}
.grid-container {
  display: grid;
  justify-content: center;
}
.grid-container {
  display: grid;
  justify-content: start;
}
.grid-container {
  display: grid;
  justify-content: end;
}
.grid-container {
  display: grid;
  justify-content: stretch;
}

 

 

9. align-content 

- Normal 기본값 (Stretch와 같음)

- flex속성의 세로 주축을 기준으로 정렬하여 배치하는 방법과 같음

.grid-container {
  display: grid;
  align-content: normal;
}
.grid-container {
  display: grid;
  align-content: space-evenly;
}
.grid-container {
  display: grid;
  align-content: space-around;
}
.grid-container {
  display: grid;
  align-content: space-between;
}
.grid-container {
  display: grid;
  align-content: center;
}
.grid-container {
  display: grid;
  align-content: start;
}
.grid-container {
  display: grid;
  align-content: end;
}
.grid-container {
  display: grid;
  align-content: stretch;
}

 

 

10. place-content

- align-content와 justify-content 동시 적용할 때 사용
- 하나의 값만 입력하면 두 속성에 모두 적용

place-content: <align-content> <justify-content>;

 

 

11. justify-items

- flex값은 flex속성에서만 사용 

 

W3Schools CSS justify-items demonstration

.anime_page justify-items legacy|left|stretch|right|normal|center|start|end|center|flex-end|flex-start|last baseline Red grid item Blue grid item Pink grid item Demo of the different values of the justify-items property.

www.w3schools.com

 

 

12. align-items

- flex값은 flex속성에서만 사용 

 

W3Schools CSS justify-items demonstration

.anime_page justify-items legacy|left|stretch|right|normal|center|start|end|center|flex-end|flex-start|last baseline Red grid item Blue grid item Pink grid item Demo of the different values of the justify-items property.

www.w3schools.com

 

 

13. place-items

place-items: <align-items> <justify-items>;
 

W3Schools CSS place-items demonstration

#container place-items normal legacy| stretch| start| end| center| baseline| center end| stretch end| end stretch| baseline| end start Demo of the different values of the place-items property.

www.w3schools.com

 

 

 

 

 

 

참고사이트

 

CSS Grid Layout Module Level 1

 

www.w3.org

 

728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함