[TIL] 220203

Lee Syong·2022년 2ė›” 3ėž
0

TIL

ëŠĐ록 ëģīęļ°
168/204
post-thumbnail

📝 ė˜Ī늘 한 ęēƒ

  1. grid

📚 ë°°ėšī ęēƒ

1. grid

1) rows and columns

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;
}

2) shortcut

grid-column-start(end)ė™€ grid-row-start(end)ëĨž ėĪ„ė—Ž ė“ļ ėˆ˜ ėžˆë‹Ī.

(1) grid-column / grid-row

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;
}

(2) 끝ėī ė–ī딘ė§€ ëŊļëĶŽ ė•Œ ėˆ˜ ė—†ė„ 때 ėŒėˆ˜ę°’ ė‚ŽėšĐ

ė˜ˆëĨž ë“Īė–ī, 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;
}

(3) span

ė‹œėž‘ęģž 끝 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;

3) lineė— ėīëĶ„ ė§“ęļ°

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;

âœĻ ë‚īėž 할 ęēƒ

  1. grid
profile
ëŠĨ동ė ėœžëĄœ ė‚īėž, 행ëģĩ하ęēŒðŸ˜

0개ė˜ 댓ęļ€