Grid- container

๊น€์˜ˆํฌยท2023๋…„ 7์›” 15์ผ
0

๐Ÿงฉ container์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์†์„ฑ๋“ค์ด๋‹ค.

grid-template-rows, grid-template-columns

grid์˜ rows์™€ columns์˜ ๋„ˆ๋น„๋ฅผ ์ง€์ •ํ•œ๋‹ค.

.container {
border: 5px dashed orange;
display: grid;
grid-template-columns: 80px 50px 50px;
}

=> ์„ธ ๊ฐœ์˜ columns์ด ๊ฐ๊ฐ 80px, 50px, 50px์˜ ๋„ˆ๋น„๋ฅผ ๊ฐ–๊ฒŒ ๋œ๋‹ค. rows๋„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉํ•˜๋ฉด ๋œ๋‹ค.

โœ”๏ธ๋น„์œจ๋กœ ์„ค์ •ํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š”fr (fraction)์„ ์‚ฌ์šฉํ•œ๋‹ค.

grid-template-columns: 1fr 1fr 1fr;

โœ”๏ธ๋” ๊ฐ„๋‹จํžˆ ์ ๊ณ ์‹ถ์„ ๋•Œ๋Š” repeat(columns/rows๊ฐœ์ˆ˜, ๋„ˆ๋น„)๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

grid-template-columns: repeat(4,80px);

grid-template-area

grid์˜ ๊ฐ cells์—๊ฒŒ ์ด๋ฆ„ํ‘œ๋ฅผ ๋ถ™์—ฌ์„œ ์›ํ•˜๋Š” ์œ„์น˜์™€ ๋น„์œจ๋กœ grid๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

html์—์„œ๋Š” class๋กœ ๊ฐ cell์„ ๊ตฌ๋ถ„์ง€์–ด ๋†“๊ณ  (header, main, sidebar, footer...), css์—์„œ ๊ฐ class๋ฅผ grid-area๋กœ ์ด๋ฆ„ํ‘œ๋ฅผ ๋ถ™์—ฌ์ค€๋‹ค.

.header {
	grid-area: hd;
}

๊ทธ๋ฆฌ๊ณ  container์— grid-template-areas๋กœ grid๋ฅผ ๋งŒ๋“ค์–ด ์ค€๋‹ค.

grid-template-areas:
	"hd hd hd hd"
    "ma ma . sb"
    "ft ft ft ft"

=> header๊ฐ€ 4์นธ, main์ด 2์นธ + ๋นˆ์นธ + sidebar๊ฐ€ 1์นธ, footer๊ฐ€ 4์นธ์ธ grid๊ฐ€ ์™„์„ฑ๋œ๋‹ค.


row-gap, column-gap

row-gap: 20px;
column-gap: 50px;

=> rows ์‚ฌ์ด์— 20px, columns ์‚ฌ์ด์— 50px์˜ ์—ฌ๋ฐฑ์ด ์ƒ๊ธด๋‹ค.

๊ฐ„๋‹จํžˆ ํ•œ ์ค„๋กœ ์“ฐ๊ณ  ์‹ถ์„ ๋•Œ๋Š”

gap: 20px 50px;

=> ์ˆœ์„œ๋Š” row, column


grid-auto-rows, grid-auto-columns

template์˜ ์‚ฌ์ด์ฆˆ๊ฐ€ ๋ฏธ๋ฆฌ ์ง€์ •๋˜์–ด ์žˆ๋Š”๋ฐ, ๊ทธ ์‚ฌ์ด์ฆˆ๋ฅผ ๋„˜์–ด์„œ rows/columns์ด ์ƒ์„ฑ๋  ๋•Œ ์–ด๋–ค ์‚ฌ์ด์ฆˆ๋กœ ๋„ฃ์–ด์•ผ ํ• ์ง€ ์•”์‹œ์ ์œผ๋กœ ์•Œ๋ ค์ค€๋‹ค.

grid-auto-rows: 100px;

=> 100px ๋„ˆ๋น„์˜ row๋ฅผ ๋„ฃ์–ด๋ผ.


grid-auto-flow

ํ•œ์ •๋œ container ์‚ฌ์ด์ฆˆ ์•ˆ์—์„œ ๋‹ค์–‘ํ•œ ์‚ฌ์ด์ฆˆ๋ฅผ ๊ฐ€์ง„ row์™€ column๋กœ ์ธํ•ด ์ค‘๊ฐ„์— ๋นˆ๊ณต๊ฐ„์ด ์ƒ๊ธธ ๋•Œ๊ฐ€ ์žˆ๋‹ค.

ex) ๊ฐ€๋กœ ๊ธธ์ด๊ฐ€ 10px์ธ container์—์„œ column 1,2,3๊ฐ€ ๊ฐ๊ฐ 3px, 3px, 5px์ธ ๊ฒฝ์šฐ column 3์€ ๋‘๋ฒˆ์งธ ์ค„๋กœ ๋„˜์–ด๊ฐ€๊ฒŒ ๋ผ์„œ ์ฒซ๋ฒˆ์งธ ์ค„์— ๋นˆ ๊ณต๊ฐ„์ด ์ƒ๊ธด๋‹ค.

๊ทธ๋Ÿด๋•Œ ๊ทธ ๋‹ค์Œ์œผ๋กœ ์žˆ๋Š”, ๋นˆ ๊ณต๊ฐ„์— ๋”ฑ ๋งž๋Š” row/column์ด ๋นˆ ๊ณต๊ฐ„์„ ์ฑ„์šธ ์ˆ˜ ์žˆ๋‹ค.

grid-auto-flow: dense;
grid-auto-flow: row dense;
grid-auto-flow: column dense;

grid (shorthand)

/์„ ๊ธฐ์ค€์œผ๋กœ ์•ž์—๋Š” row, ๋’ค์—๋Š” column์˜ ๋‚ด์šฉ์„ ์ ์–ด์ค€๋‹ค.

grid: auto-flow / 1fr 1fr 1fr;
grid: auto-flow dense / 40px 40px 1fr;

๐Ÿงฉ template => ๋ช…์‹œ์ 
๐Ÿงฉ auto => ์•”์‹œ์ 

โ—๏ธ3๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

  • row/column ๋‘˜ ๋‹ค ๋ช…์‹œ์ ์ธ ๊ฒฝ์šฐ
  • row: ๋ช…์‹œ์  column: ์•”์‹œ์ 
  • row: ์•”์‹œ์  column: ๋ช…์‹œ์ 

justify-content

flexbox์ฒ˜๋Ÿผ grid์—๋„ space-around์™€ space-between์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

โ—๏ธ๋ฐ”๊นฅ์˜ container์˜ ํฌ๊ธฐ๊ฐ€ ์•ˆ์˜ content๋ณด๋‹ค ์ปค์„œ ๋‚จ๋Š” ๊ณต๊ฐ„์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

justify-content: space-around;
=> content ์ฃผ๋ณ€์œผ๋กœ (์™ผ์ชฝ ๋, ์˜ค๋ฅธ์ชฝ ๋ ํฌํ•จ) ๋™์ผํ•œ ๊ฐ„๊ฒฉ์ด ์ฃผ์–ด์ง„๋‹ค
justify-content: space-between;
=> content ์‚ฌ์ด์— ๋™์ผํ•œ ๊ฐ„๊ฒฉ์ด ์ฃผ์–ด์ง„๋‹ค.
justify-content: center;
=> ๊ฐ€๋กœ์˜ ๊ฐ€์šด๋ฐ์— ์œ„์น˜ํ•œ๋‹ค.


align-content

๊ต์ฐจ์ถ•์„ ๊ธฐ์ค€์œผ๋กœ content๋ฅผ ์–ด๋А ์œ„์น˜์— ๋†“์„์ง€ ์ง€์ •ํ•œ๋‹ค.

align-content: end; : ์™ผ์ชฝ ๋งจ ์•„๋ž˜ ์œ„์น˜ํ•œ๋‹ค.
align-content: center; : ์„ธ๋กœ์˜ ๊ฐ€์šด๋ฐ์— ์œ„์น˜ํ•œ๋‹ค.
space-around, space-between๋„ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค => ์„ธ๋กœ์— ๊ฐ„๊ฒฉ์„ ์ค€๋‹ค.


justify-items, align-items

grid์˜ ํ•œ ์นธ ์•ˆ์—์„œ ์•„์ดํ…œ์„ ์–ด๋–ป๊ฒŒ ์ •๋ ฌํ• ์ง€ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

justify-items: start; : ํ•œ ์นธ์˜ ์‹œ์ž‘์  (์™ผ์ชฝ ์œ„)์— ์•„์ดํ…œ์ด ๋ถ™๊ฒŒ ๋œ๋‹ค.
justify-items: center; : ํ•œ ์นธ์˜ ๊ฐ€๋กœ์˜ ๊ฐ€์šด๋ฐ์— ์•„์ดํ…œ์ด ์œ„์น˜ํ•œ๋‹ค.
๊ธฐ๋ณธ๊ฐ’: justify-items: stretch;

โœ”๏ธ align-items๋„ ๋™์ผํ•˜๊ฒŒ ์ž‘๋™ํ•˜๊ณ  ์„ธ๋กœ ์ถ• ์•ˆ์—์„œ ์ •๋ ฌ๋œ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€