grid container์ grid-template-areas๋ฅผ ์ง์ ํ๊ณ grid item์ grid-area๋ฅผ ๋ถ์ฌํ๋ ๋์
grid item์ grid-column-start(end)
์ grid-row-start(end)
๋ฅผ ์ฌ์ฉํ ์๋ ์๋ค.
ํ์์ ๊ฒฝ์ฐ grid container์ gap ํ๋กํผํฐ
๋ฅผ ์ฌ์ฉํด์ ์ํ๋ ๋ชจ์์ ๋ ์ด์์์ ๋ ์ฝ๊ฒ ๋ง๋ค ์ ์๋ค.
๋ฌผ๋ก ์ ์์ ๊ฒฝ์ฐ์๋ gap ํ๋กํผํฐ๋ฅผ ์ฌ์ฉํ ์ ์์ง๋ง ์ํ๋ ๋ชจ์์ ๋ ์ด์์์ ๋ง๋ค๊ธฐ์ ํ์๊ฐ ๋ ์ฝ๋ค.
<div class="grid">
<div class="header"></div>
<div class="content"></div>
<div class="nav"></div>
<div class="footer"></div>
</div>
์ฃผ์ ์ฒ๋ฆฌ๋ ๋ถ๋ถ์ด grid-template-areas์ grid-area๋ฅผ ์ฌ์ฉํ์ ๋์ ์ฝ๋์ด๋ค.
.grid {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
gap: 10px;
}
.header {
background-color: lightpink;
grid-column-start: 1;
grid-column-end: 5;
grid-row-start: 1;
grid-row-end: 2;
}
.content {
background-color: lightskyblue;
grid-column-start: 1;
grid-column-end: 4;
grid-row-start: 2;
grid-row-end: 4;
}
.nav {
background-color: lightseagreen;
grid-column-start: 4;
grid-column-end: 5;
grid-row-start: 2;
grid-row-end: 4;
}
.footer {
background-color: mediumaquamarine;
grid-column-start: 1;
grid-column-end: 5;
grid-row-start: 4;
grid-row-end: 5;
}
grid-column-start(end)์ grid-row-start(end)๋ฅผ ์ค์ฌ ์ธ ์ ์๋ค.
start์ end๋ฅผ ๋ฐ๋ก ์ธ ํ์ ์์ด ๋ค์๊ณผ ๊ฐ์ด ์ค์ผ ์ ์๋ค.
.grid {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
gap: 10px;
}
.header {
background-color: lightpink;
grid-column: 1 / 5;
grid-row: 1 / 2;
}
.content {
background-color: lightskyblue;
grid-column: 1 / 4;
grid-row: 2 / 4;
}
.nav {
background-color: lightseagreen;
grid-column: 4 / 5;
grid-row: 2 / 4;
}
.footer {
background-color: mediumaquamarine;
grid-column: 1 / 5;
grid-row: 4 / 5;
}
์๋ฅผ ๋ค์ด, line์ด ๋ช ๊ฐ์ธ์ง, ์ด๋์ ๋๋๋์ง ์ ๊ฒฝ ์ธ ํ์ ์์ด -1์ ์ ์ผ๋ฉด ๊ทธ ์ค line์ ๋๊น์ง grid item์ด ๋ง๋ค์ด์ง๋ค.
grid-column: 1 / 5;
grid-row: 1 / 2;
์ด๋ ๋ค์๊ณผ ๊ฐ๋ค.
grid-column: 1 / -1;
grid-row: 1 / 2;
๋ค๋ฅธ ์๋ก๋, ์ค์ content๊ฐ ์ผ๋ง๋ ๊ธธ ๊ฒ์ธ์ง ๋ฏธ๋ฆฌ ์ ์ ์์ ๋ ์ฌ์ฉํ๋ฉด ์ ์ฉํ๋ค.
.content {
background-color: lightskyblue;
grid-column: 1 / 4;
grid-row: 2 / 4;
}
์ค์ ๋ก content๊ฐ 4์์ ๋๋ ์ง 7์์ ๋๋ ์ง ๋ชจ๋ฅผ ๋ -2๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฌด์กฐ๊ฑด ๋์์ 2๋ฒ์งธ line๊น์ง grid item์ด ๋ง๋ค์ด์ง๋ค.
.content {
background-color: lightskyblue;
grid-column: 1 / -2;
grid-row: 2 / -2;
}
์์๊ณผ ๋ line์ ์ ๋ ๋์ ์ span์ ์ฌ์ฉํ ์ ์๋ค.
์ผ๋ง๋ ๋ง์ grid cell์ ๊ฐ์ง๊ณ ์๋๊ฐ๋ฅผ ์ ๋ ๊ฒ์ด๋ค.
.header {
background-color: lightpink;
grid-column: 1 / -1;
grid-row: span 1;
}
.content {
background-color: lightskyblue;
grid-column: 1 / -2;
grid-row: span 2;
}
ํ์ํ ๊ฒฝ์ฐ ์์ line์ ์์ ํจ๊ป ์ ์ด์ค ์ ์๋ค.
grid-row: 1 / span 1;
span์ด ์๋๋ผ line์ ์ฌ์ฉํ๊ณ ์ ํ ๋
ํ์๋ ์๋๊ณ ์ ํ ์ฌํญ์ด์ง๋ง line์ ์ด๋ฆ์ ์ง์ด์ค ์๋ ์๋ค.
.grid {
display: grid;
grid-template-columns: [first-line] 100px [second-line] 100px [third-line] 100px [fourth-line] 100px [fifth-line];
grid-template-rows: repeat(4, 100px [line]);
gap: 10px;
}
.header {
background-color: lightpink;
grid-column: first-line / fifth-line;
grid-row: 1 / line 1;
}
.content {
background-color: lightskyblue;
grid-column: first-line / fourth-line;
grid-row: line 1 / line -2;
}
.nav {
background-color: lightseagreen;
grid-column: fourth-line / fifth-line;
grid-row: line 1 / line -2;
}
.footer {
background-color: mediumaquamarine;
grid-column: first-line / fifth-line;
grid-row: line 3 / line 4;
}
์ด๋ repeat(4, 100px [line])์์ 100px [line]
์ด๋ผ๊ณ ํ๊ธฐ ๋๋ฌธ์ ์ต์ข
grid container์์ ๋งจ ์ line์ ์ด๋ฆ ์ง์ด์ค [line]์ ํด๋น๋์ง ์๋๋ค.
grid container์ ๋งจ ์ line์ ๊ฐ์ ธ์ค๊ธฐ ์ํด์๋ ์ด๋ฅผ ์๋ฏธํ๋ 1์ ์ ์ด์ผ ํ๋ค.
grid-row: 1 / line 1;