๐งฉ container์ ์ฌ์ฉํ ์ ์๋ ์์ฑ๋ค์ด๋ค.
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์ ๊ฐ 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: 20px; column-gap: 50px;
=> rows ์ฌ์ด์ 20px, columns ์ฌ์ด์ 50px์ ์ฌ๋ฐฑ์ด ์๊ธด๋ค.
๊ฐ๋จํ ํ ์ค๋ก ์ฐ๊ณ ์ถ์ ๋๋
gap: 20px 50px;
=> ์์๋ row, column
template์ ์ฌ์ด์ฆ๊ฐ ๋ฏธ๋ฆฌ ์ง์ ๋์ด ์๋๋ฐ, ๊ทธ ์ฌ์ด์ฆ๋ฅผ ๋์ด์ rows/columns์ด ์์ฑ๋ ๋ ์ด๋ค ์ฌ์ด์ฆ๋ก ๋ฃ์ด์ผ ํ ์ง ์์์ ์ผ๋ก ์๋ ค์ค๋ค.
grid-auto-rows: 100px;
=> 100px ๋๋น์ row๋ฅผ ๋ฃ์ด๋ผ.
ํ์ ๋ 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;
/์ ๊ธฐ์ค์ผ๋ก ์์๋ row, ๋ค์๋ column์ ๋ด์ฉ์ ์ ์ด์ค๋ค.
grid: auto-flow / 1fr 1fr 1fr;
grid: auto-flow dense / 40px 40px 1fr;
๐งฉ template => ๋ช ์์
๐งฉ auto => ์์์
โ๏ธ3๊ฐ์ง ๊ฒฝ์ฐ๊ฐ ์๋ค.
flexbox์ฒ๋ผ grid์๋ space-around์ space-between์ ์ฌ์ฉํ ์ ์๋ค.
โ๏ธ๋ฐ๊นฅ์ container์ ํฌ๊ธฐ๊ฐ ์์ content๋ณด๋ค ์ปค์ ๋จ๋ ๊ณต๊ฐ์ด ์์ด์ผ ํ๋ค.
justify-content: space-around;
=> content ์ฃผ๋ณ์ผ๋ก (์ผ์ชฝ ๋, ์ค๋ฅธ์ชฝ ๋ ํฌํจ) ๋์ผํ ๊ฐ๊ฒฉ์ด ์ฃผ์ด์ง๋ค
justify-content: space-between;
=> content ์ฌ์ด์ ๋์ผํ ๊ฐ๊ฒฉ์ด ์ฃผ์ด์ง๋ค.
justify-content: center;
=> ๊ฐ๋ก์ ๊ฐ์ด๋ฐ์ ์์นํ๋ค.
๊ต์ฐจ์ถ์ ๊ธฐ์ค์ผ๋ก content๋ฅผ ์ด๋ ์์น์ ๋์์ง ์ง์ ํ๋ค.
align-content: end;
: ์ผ์ชฝ ๋งจ ์๋ ์์นํ๋ค.
align-content: center;
: ์ธ๋ก์ ๊ฐ์ด๋ฐ์ ์์นํ๋ค.
space-around, space-between๋ ๋์ผํ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค => ์ธ๋ก์ ๊ฐ๊ฒฉ์ ์ค๋ค.
grid์ ํ ์นธ ์์์ ์์ดํ ์ ์ด๋ป๊ฒ ์ ๋ ฌํ ์ง ์ง์ ํ ์ ์๋ค.
justify-items: start;
: ํ ์นธ์ ์์์ (์ผ์ชฝ ์)์ ์์ดํ ์ด ๋ถ๊ฒ ๋๋ค.
justify-items: center;
: ํ ์นธ์ ๊ฐ๋ก์ ๊ฐ์ด๋ฐ์ ์์ดํ ์ด ์์นํ๋ค.
๊ธฐ๋ณธ๊ฐ:justify-items: stretch;
โ๏ธ align-items๋ ๋์ผํ๊ฒ ์๋ํ๊ณ ์ธ๋ก ์ถ ์์์ ์ ๋ ฌ๋๋ค.