๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
CSS๐Ÿ”ง/๋ฐ˜์‘ํ˜•

04_display grid

by hyojinny 2022. 11. 14.

flex ๋Š” ํ•œ๋ฐฉํ–ฅ ๋ ˆ์ด์•„์›ƒ (ํ•œ๋ฐฉํ–ฅ) ์ต์Šค ์ผ๋ถ€ ๋จน์Œ

grid ๋‘๋ฐฉํ–ฅ ๋ ˆ์ด์•„์›ƒ (๊ฐ€๋กœ ์„ธ๋กœ ๋‘˜๋‹ค๊ฐ€๋Šฅ) ์ข€๋” ๋ณต์žกํ•œ ํ–‰๋ ฌ๊ตฌ์กฐ (ํ‘œ) ๊ตฌํ˜„ ๊ฐ€๋Šฅ

์ต์Šค์—์„œ ์•„์˜ˆ ์•ˆ๋จน์Œ

 

*๋ณ‘ํ•ฉ๊ตฌ์กฐ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ ํŽธํ•˜๋‹ค

 

 

 

 

 

 

 

 

 

 

grid-template-rows
grid-template-columns (์นธ์˜๊ฐœ์ˆ˜)

.container {
	grid-template-columns: 200px 200px 500px;
	/* grid-template-columns: 1fr 1fr 1fr */
	/* grid-template-columns: repeat(3, 1fr) */
	/* grid-template-columns: 200px 1fr */
	/* grid-template-columns: 100px 200px auto */

	grid-template-rows: 200px 200px 500px;
	/* grid-template-rows: 1fr 1fr 1fr */
	/* grid-template-rows: repeat(3, 1fr) */
	/* grid-template-rows: 200px 1fr */
	/* grid-template-rows: 100px 200px auto */
}

 

 

1fr 

์ „์šฉ ๋น„์œจ๋‹จ์œ„ ์‚ฌ์šฉ

columns ์นธ์˜ ๊ฐฏ์ˆ˜ 

row ํ–‰

 

 

% calc ์•ˆ์จ๋„๋จ

 

 

gap

.container {
	gap: 10px 20px;
	/* row-gap: 10px; column-gap: 20px; */
}

ํ–‰๊ฐ„์˜ ๊ฐ„๊ฒฉ (์‚ฌ์ด์—๋งŒ ๊ฐ„๊ฒฉ์ด๋“ค์–ด๊ฐ)

 

 

 

 

.container {
	grid-auto-rows: minmax(100px, auto);
}

 

๊ฐ€๋ณ€์ผ๋–„ auto ์‚ฌ์šฉ ํ–‰์—ด์˜ ์ „์ฒดํฌ๊ธฐ๋ฅผ ํ•œ๋ฒˆ์— ์žก์„์ˆ˜ ์žˆ์Œ

 

 

 

 

๋ณ‘ํ•ฉ

 

1-3์นธ์„ ํ•ฉ์ณ๋ผ 

 

 

์„ธ๋กœ ์ •๋ ฌ

.container {
	align-items: stretch;
	/* align-items: start; */
	/* align-items: center; */
	/* align-items: end; */
}

 

 

๊ฐ€๋กœ์ •๋ ฌ

.container {
	justify-items: stretch;
	/* justify-items: start; */
	/* justify-items: center; */
	/* justify-items: end; */
}

 

itmes ๋Š” ๊ฐœ๋ณ„์ •๋ ฌ

content ๋Š” ์ „์ฒด์ •๋ ฌ

 

 

 

z-index ๊ฐ€๋Šฅ

 


 

 

 

display: grid;
- IE11์—์„œ ์‚ฌ์šฉ๋ถˆ๊ฐ€ํ•˜๋ฏ€๋กœ ๋ชจ๋ฐ”์ผํ”Œ์ ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ
- ํ”„๋ก ํŠธ๊ฐœ๋ฐœํ™˜๊ฒฝ(React, Vue)์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅ
- ์ปจํ…์ธ ๊ฐ€ ํ–‰, ์—ด ๊ตฌ์กฐ์ด๋ฉฐ ์ผ๋ถ€์ปจํ…์ธ ์˜ ํฌ๊ธฐ๊ฐ€ ๋‹ค๋ฅผ๊ฒฝ์šฐ(๋ณต์žก)

๋ถ€๋ชจ์ปจํ…Œ์ด๋„ˆ {
  display:grid;
  /* ์—ฌ๋Ÿฌ์ค„์ด๋”๋ผ๋„ ํ•œ์ค„์ธ 1fr๋กœ ์ฒ˜๋ฆฌ๊ฐ€๋Šฅ */
  grid-template-rows: 1fr 1fr 1fr;
  /* 3์นธ์œผ๋กœ ์ง€์ •ํ•˜๊ณ  ํฌ๊ธฐ๋Š” ๋™์ผ, fr์€ fraction(๋น„์œจ) */
  grid-template-columns: 1fr 1fr 1fr;
  /* ์ฒซ๋ฒˆ์งธ์นธ: 3/5, ๋‘๋ฒˆ์งธ์นธ: 2/5 */
  grid-template-columns: 3fr 2fr;
  /* 3์นธ์œผ๋กœํ•˜๊ณ  ๊ฐ€๋กœ๊ธธ์ด ๋™์ผํ•˜๊ฒŒ */
  grid-template-columns: repeat(3, 1fr);
  /* ์ค„๊ฐ„๊ฒฉ, ์นธ๊ฐ„๊ฒฉ, ๊ฐ ์ค„๊ณผ ์นธ์‚ฌ์ด๋งŒ ์ ์šฉ๋จ */
  gap: 10px 20px;
  /* ์„ธ๋กœ์ •๋ ฌ */
  align-items: center;
  /* ๊ฐ€๋กœ์ •๋ ฌ */
  justify-content: center;
}

๊ทธ๋ฆฌ๋“œ์•„์ดํ…œ {
  /* ํ•ฉ์น˜๊ณ  ์‹ถ์€ ์‹œ์ž‘๋ฒˆํ˜ธ์™€ ๋๋ฒˆํ˜ธ๋ฅผ ์ ์Œ */
  grid-row: 1 / 3;
  grid-column: 1 / 3;
  /* 1๋ฒˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๋‘์นธ ํ•ฉ์น˜๊ธฐ */
  grid-column: 1 / span 2;
  /* 1๋ฒˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๋‘์นธ ํ•ฉ์นจ, ์‹œ์ž‘๋ฒˆํ˜ธ ์ƒ๋žต์‹œ 1๋ถ€ํ„ฐ ์‹œ์ž‘ */
  grid-column: span 2;
  /* z-index, order ์‚ฌ์šฉ๊ฐ€๋Šฅ */
  /* ํ–‰์‹œ์ž‘, ์—ด์‹œ์ž‘, ํ–‰๋, ์—ด๋๋ฒˆํ˜ธ */
  grid-area:1 / 2 / 4 / 6;
}

 

 

 

 

 

 

 

 

 

 

 


์ฐธ๊ณ  ๋งํฌ 

https://studiomeal.com/archives/533

 

์ด๋ฒˆ์—์•ผ๋ง๋กœ CSS Grid๋ฅผ ์ตํ˜€๋ณด์ž

์ด ํฌ์ŠคํŠธ์—๋Š” ์‹ค์ œ ์ฝ”๋“œ๊ฐ€ ์ ์šฉ๋œ ๋ถ€๋ถ„๋“ค์ด ์žˆ์œผ๋ฏ€๋กœ, ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ์ž˜ ์ง€์›ํ•˜๋Š” ์ตœ์‹  ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ณด์‹œ๋Š”๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. (๋Œ€์ถฉ ์ธํ„ฐ๋„ท ์ต์Šคํ”Œ๋กœ๋Ÿฌ๋กœ๋งŒ ์•ˆ๋ณด๋ฉด ๋œ๋‹ค๋Š” ์ด์•ผ๊ธฐ) ์ด ํŠœํ† ๋ฆฌ์–ผ์€ “

studiomeal.com

 

๋Œ“๊ธ€