1. CSS Declarations ๐Ÿ‘ฉโ€

  • ๋‚ด์žฅ ๋ฐฉ์‹
  • ๋งํฌ ๋ฐฉ์‹
  • ์ธ๋ผ์ธ ๋ฐฉ์‹
  • @import ๋ฐฉ์‹
  1. ๋‚ด์žฅ ๋ฐฉ์‹ : HTML ์˜ head ์•ˆ์— style ์—˜๋ฆฌ๋จผํŠธ์˜ content ๋กœ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ์‹.
  2. ์ธ๋ผ์ธ ๋ฐฉ์‹ : HTML ์˜ ์—˜๋ฆฌ๋จผํŠธ์— ์†์„ฑ์œผ๋กœ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ์‹.
  3. ๋งํฌ ๋ฐฉ์‹ : HTML ์˜ head ์•ˆ์— link ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ์™ธ๋ถ€ CSS ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ์‹.
  4. @import ๋ฐฉ์‹ : @import "reset.css" ๋˜๋Š” @import url("reset.css")์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•œ๋‹ค.

๋งํฌ๋ฐฉ์‹์€ HTML ์ด ํ•ด์„๋˜๋ฉฐ async๋กœ ์ž‘๋™ํ•ด ์—ฌ๋Ÿฌ ๊ฐœ๋ฅผ ๋™์‹œ์— ์š”์ฒญํ•˜๊ณ , ์ˆ˜์‹  ํ•˜๋Š” ๋Œ€๋กœ ํ•ด์„ํ•œ๋‹ค. ๋ฐ˜๋ฉด @import๋ฐฉ์‹์€ ๋จผ์ € ์š”์ฒญํ•œ CSS ์˜ ์ˆ˜์‹ ์ด ๋๋‚˜๊ณ  ํ•ด์„์„ ํ•˜๋Š” ๊ณผ์ •์— @import๋ฅผ ๋ณด๊ณ  ์š”์ฒญ์„ ํ•œ๋‹ค. including ๋˜๋Š” ๋ฐฉ์‹์ด ์•„๋‹ˆ๊ณ  lazy loading ๋˜๋Š” ๋ฐฉ์‹์ด๋ผ ์ผ๋ถ€๋Ÿฌ ์—ฐ๊ฒฐ์„ ์ง€์—ฐ์‹œํ‚ค๋Š” ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์œผ๋‚˜, ์ œ์–ดํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋‹ˆ๋‹ค. ๋ณ„๋„์˜ ๋ฒˆ๋“ค๋ง์ด๋‚˜ ๋นŒ๋“œ ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•ด include ์‹œํ‚ค๊ณ  ์ง€์—ฐ ์‹คํ–‰์ด ํ•„์š”ํ•˜๋ฉด JavaScript ๋กœ ์ œ์–ด๋ฅผ ํ•ด์•ผ ํ•œ๋‹ค.


2. CSS Selectors ๐Ÿ‘ฉโ€

1. Basic Selectors

  • Universal Selector(์ „์ฒด ์„ ํƒ์ž)
* {
  color: red;
}
  • Type Selector(ํƒœ๊ทธ ์„ ํƒ์ž)
li {
  color: red;
}
  • Class Selector(ํด๋ž˜์Šค ์„ ํƒ์ž)
.orange {
  color: orange;
}
  • ID Selector(์•„์ด๋”” ์„ ํƒ์ž)
#orange {
  color: orange;
}

Universal > Type > Class > ID ์ˆœ์„œ๋กœ ์ ์šฉ๋œ๋‹ค. ์ข€ ๋” ์ž์„ธํ•œ CSS ์šฐ์„  ์ˆœ์œ„๋Š” CSS Specificity๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

2. Combinators

  • Basic Combinator(์ผ์น˜ ์„ ํƒ์ž)
span.orange {
  color: orange;
}
  • Child Combinator(์ž์‹ ์„ ํƒ์ž)
ul > .orange {
  color: orange;
}
  • Descendant Combinator(์ž์† ์„ ํƒ์ž)
div .orange {
  color: orange;
}
  • Adjacent Sibling Combinator(์ธ์ ‘ ํ˜•์ œ ์„ ํƒ์ž)
.orange + li {
  color: orange;
}

๋‹ค์Œ ํ˜•์ œ ์—˜๋ฆฌ๋จผํŠธ ํ•˜๋‚˜๋งŒ ์„ ํƒ.

  • General Sibling Combinator(์ผ๋ฐ˜ ํ˜•์ œ ์„ ํƒ์ž)
.orange ~ li {
  color: red;
}

๋‹ค์Œ ํ˜•์ œ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ชจ๋‘๋ฅผ ์„ ํƒ.

3. Pseudo-class

๊ฐ€์ƒ ํด๋ž˜์Šค ์„ ํƒ์ž๋Š” ๋™์ž‘๊ณผ ๊ด€๋ จ๋œ ๊ฒƒ๊ณผ ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒƒ ๋‘ ๊ฐ€์ง€๋กœ ๋ถ„๋ฅ˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

1 ) ๋™์ž‘๊ณผ ๊ด€๋ จ๋œ ๊ฐ€์ƒ ํด๋ž˜์Šค ์„ ํƒ์ž

  • hover

๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ ค ๋†“์€ ์ƒํƒœ.

.box {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition: 1s;
}

.box:hover {
  width: 300px;
  background-color: cornflowerblue;
}
  • active

๋งˆ์šฐ์Šค๋กœ ํด๋ฆญ์„ ์œ ์ง€ ์ค‘์ธ ์ƒํƒœ.

.box {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition: 1s;
}

.box:hover {
  width: 300px;
  background-color: cornflowerblue;
}
  • focus

๋งˆ์šฐ์Šค๋‚˜ Tabํ‚ค์— ์˜ํ•ด HTML ๋Œ€ํ™”ํ˜• ์ฝ˜ํ…์ธ (Interactive Content)๊ฐ€ ํฌ์ปค์Šค ๋œ ์ƒํƒœ.

input:focus {
  background-color: darkseagreen;
}

input, a, button, label, select์™€ ๊ฐ™์€ ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ํ•ด๋‹น๋˜๋ฉฐ, HTML ๋Œ€ํ™”ํ˜• ์ฝ˜ํ…์ธ ๊ฐ€ ์•„๋‹ˆ๋”๋ผ๋„ tabindex ์†์„ฑ์„ ์‚ฌ์šฉํ•œ ์—˜๋ฆฌ๋จผํŠธ๋„ focus๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค.

<div class="box" tabindex="-1"></div>

tabindex="-1" ์†์„ฑ์„ ์ฃผ๋ฉด ๊ฐ•์ œ๋กœ ํฌ์ปค์Šค๊ฐ€ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ—ˆ์šฉํ•œ๋‹ค. ํ‚ค๋ณด๋“œ์˜ Tabํ‚ค๋กœ ํฌ์ปค์Šค ๊ฐ€๋Šฅํ•œ ๋Œ€์ƒ์˜ index๋ฅผ ๊ฐ•์ œ๋กœ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์œผ๋กœ, -1์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๊ฐ’์„ ์ฃผ๋ฉด Tabํ‚ค์— ์„ ํƒ๋˜๋ฏ€๋กœ ๋…ผ๋ฆฌ์  ํ๋ฆ„์„ ๋ฐฉํ•ดํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ํ‚ค๋ณด๋“œ์˜ Tabํ‚ค์— ์˜ํ—ค ํฌ์ปค์Šค ๋  ํ•„์š”๊ฐ€ ์—†๋‹ค๋ฉด -1์„ ์ฃผ์–ด ํ๋ฆ„์„ ๋ฐฉํ•ดํ•˜์ง€ ์•Š๋„๋ก ํ•ด์•ผํ•œ๋‹ค.


2 ) ๋™์ž‘๊ณผ ๊ด€๋ จ๋˜์ง€ ์•Š์€ ๊ฐ€์ƒ ํด๋ž˜์Šค ์„ ํƒ์ž

  • first-child, last-child, nth-child, โ€ฆ, nth-of-type
<div class="fruits">
  <span>๋”ธ๊ธฐ</span>
  <span>์ˆ˜๋ฐ•</span>
  <div>๋ฐฐ</div>
  <p>๋ง๊ณ </p>
  <div>์˜ค๋ Œ์ง€</div>
  <h3>์‚ฌ๊ณผ</h3>
</div>
.fruits span:first-child {
  color: orange;
}

first-child๊ฐ€ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

.fruits span {
  &:first-child {
    color: orange;
  }
}

.fruits์˜ ์ž์‹ ์ค‘ span์ธ ๊ฒƒ ์ค‘ ์ฒซ ๋ฒˆ์งธ๊ฐ€ ์•„๋‹ˆ๋ผ, .fruits์˜ ์ž์‹ ์ค‘ span์ด๋ฉด์„œ ์ฒซ ๋ฒˆ์งธ ์ž์‹์ธ ๊ฒƒ. ์ฆ‰ And์˜ ๊ฐœ๋…์ด๋‹ค. ๋”ฐ๋ผ์„œ ๋”ธ๊ธฐ๊ฐ€ ์„ ํƒ๋œ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ๋ฅผ ์‚ดํŽด๋ณด์ž.

.fruits div:first-child {
  color: orange;
}

.fruits์˜ ์ž์‹ ์ค‘ div์ธ ๊ฒƒ์€ ์ฐพ์•˜์œผ๋‚˜, ์ด๊ฒƒ์ด ์ฒซ ๋ฒˆ์งธ ์ž์‹์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ผ์น˜ํ•˜๋Š” ๋Œ€์ƒ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋งŒ์•ฝ, .fruits์˜ ์ž์‹ ์ค‘ div์ธ ๊ฒƒ ์ค‘ ์ฒซ ๋ฒˆ์งธ๋ฅผ ์„ ํƒํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด first-of-type์„ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

.fruits div:first-of-type {
  color: orange;
}

๋”ฐ๋ผ์„œ ๋ฐฐ๊ฐ€ ์„ ํƒ๋œ๋‹ค.

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ last-child ์—ญ์‹œ .fruits์˜ ์ž์‹ ์ค‘ h3์ด๋ฉด์„œ ๋งˆ์ง€๋ง‰ ์ž์‹์ธ ๊ฒƒ์„ ์„ ํƒํ•œ๋‹ค.

.fruits h3:last-child {
  color: orange;
}

๋”ฐ๋ผ์„œ ์‚ฌ๊ณผ๊ฐ€ ์„ ํƒ๋œ๋‹ค.


nth-child, nth-of-type์— *๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ๋“ค์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

.fruits *:nth-child(even) {
  color: orange;
}

/* Same with
.fruits :nth-child(even) {
  color: orange;
}*/

.fruits์˜ ์ž์‹ ์ค‘ ์ง์ˆ˜๋ฒˆ์งธ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ชจ๋‘ ์„ ํƒํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, ์ˆ˜๋ฐ•, ๋ง๊ณ , ์‚ฌ๊ณผ๊ฐ€ ์„ ํƒ๋œ๋‹ค.

์‚ฌ์‹ค .fruits :nth-child(even)์™€ ๊ฐ™์ด ๊ณต๋ฐฑ์„ ์ฃผ๊ณ  ๊ฐ€์ƒ ์„ ํƒ์ž๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋™์ผํ•œ ๋Œ€์ƒ์„ ์„ ํƒํ•œ๋‹ค. ํ•˜์ง€๋งŒ ์ด ๊ฒฝ์šฐ .fruits:nth-child(even)์™€ ๊ฐ™์ด ์‹ค์ˆ˜๋กœ ๊ณต๋ฐฑ์ด ๋ˆ„๋ฝ๋  ๊ฒฝ์šฐ ์ „ํ˜€ ๋‹ค๋ฅธ ๋Œ€์ƒ์„ ์ฐพ๋Š”๋‹ค.
๋”ฐ๋ผ์„œ .fruits *:nth-child(even)์™€ ๊ฐ™์ด ๋ช…ํ™•ํžˆ ์˜๋„๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

.fruits *:nth-of-type(even) {
  color: orange;
}

/* Same with
.fruits :nth-of-type(even) {
  color: orange;
}*/

.fruits์˜ ์ž์‹ ์ค‘ ๊ฐ ํƒ€์ž…์˜ ๋‘ ๋ฒˆ์งธ๋ฅผ ์„ ํƒํ•˜๋ฏ€๋กœ, ์ˆ˜๋ฐ•๊ณผ ์˜ค๋ Œ์ง€๊ฐ€ ์„ ํƒ๋œ๋‹ค.

nth-child, first-child, last-child๋Š” <br />๊ณผ ๊ฐ™์€ ์—˜๋ฆฌ๋จผํŠธ๋„ ๋ชจ๋‘ ์ž์‹ ์—˜๋ฆฌ๋จผํŠธ์ด๊ธฐ ๋•Œ๋ฌธ์— ์„ ํƒ์— ์ฃผ์˜ํ•ด์•ผํ•œ๋‹ค. ๋ฐ˜๋ฉด, nth-of-type, first-of-type, last-of-type์€ ํ•ด๋‹น ํƒ€์ž… ์—˜๋ฆฌ๋จผํŠธ๋งŒ ์„ ํƒํ•œ๋‹ค.

nth-child์™€ nth-of-type์€ ๋ชจ๋‘ ๋“ฑ์ฐจ์ˆ˜์—ด(Arithmetic Sequence)์„ ํฌํ•จํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, CSS ์„ ํƒ์ž ์ž์ฒด๋Š” 1-based index๋ฅผ ๊ฐ–๋Š” ๊ฒƒ๊ณผ ๋‹ฌ๋ฆฌ ์‚ฐ์ˆ ์‹์— ํฌํ•จ๋˜๋Š” n์€ 0์„ ํฌํ•จํ•˜๋Š” ์ž์—ฐ์ˆ˜๋กœ 0, 1, 2, 3, ...์„ ๊ฐ–๋Š”๋‹ค.

  • not(negation selector)
.fruits *:not(div) {
  color: orange;
}

/* Same with
.fruits :not(div) {
  color: orange;
}*/

.fruits์˜ ์ž์‹ ์ค‘ span์ด ์•„๋‹Œ ๊ฒƒ์„ ๋ชจ๋‘ ์„ ํƒํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, ๋”ธ๊ธฐ, ์ˆ˜๋ฐ•, ๋ง๊ณ , ์‚ฌ๊ณผ๊ฐ€ ์„ ํƒ๋œ๋‹ค.

4. Pseudo-element

๊ฐ€์ƒ ์—˜๋ฆฌ๋จผํŠธ ์„ ํƒ์ž๋Š” ::๋ฅผ ๋ถ™์ธ๋‹ค(: ํ•˜๋‚˜๋งŒ ๋ถ™์—ฌ๋„ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ํ•ด์„์€ ํ•˜์ง€๋งŒ ํ‘œ์ค€์ด ์•„๋‹ˆ๋‹ค).

  • before && content

์—˜๋ฆฌ๋จผํŠธ์˜ content ์˜ ์•ž์ชฝ์— ๊ฐ€์ƒ์˜ ์ธ๋ผ์ธ ์†์„ฑ์˜ content ๋ฅผ ์‚ฝ์ž…ํ•œ๋‹ค. insertAdjacentElement()๋ฉ”์„œ๋“œ์˜ ํฌ์ง€์…˜ afterbegin์ด ์‚ฝ์ž…๋˜๋Š” ์œ„์น˜์™€ ๋™์ผํ•˜๋‹ค.

<!-- beforebegin -->
<div class="box">
  <!-- afterbegin -->
  foo content
  <!-- beforeend -->
</div>
<!-- afterend -->
.box::before {
  content: "before!!";
}
document.querySelector('.box').childNodes[0]  // foo content

๊ฐ€์ƒ ์—˜๋ฆฌ๋จผํŠธ๋Š” Node ์˜ ์ž์‹ ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ์•„๋‹ˆ๋‹ค.

  • after && content

before์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ content ์˜ ๋’ท์ชฝ์— ๊ฐ€์ƒ์˜ ์ธ๋ผ์ธ ์†์„ฑ์˜ content ๋ฅผ ์‚ฝ์ž…ํ•œ๋‹ค. ์œ„์น˜๋Š” beforeend๊ฐ€ ์‚ฝ์ž…๋˜๋Š” ์œ„์น˜์™€ ๋™์ผํ•˜๋‹ค.

.box::after {
  content: "after!!";
}

before์™€ after๋Š” ๋ฐ˜๋“œ์‹œ content ์†์„ฑ์„ ๊ฐ€์ ธ์•ผํ•œ๋‹ค.


๊ฐ€์„ฑ ์—˜๋ฆฌ๋จผํŠธ ์„ ํƒ์ž๋Š” ๋‹จ์ง€ ์ธ๋ผ์ธ ํ…์ŠคํŠธ๋ฅผ ์‚ฝ์ž…ํ•˜๋Š” ๊ฒƒ ๋ฟ ์•„๋‹ˆ๋ผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

<div class="container">
  <div class="box">foo</div>
  <div class="box">bar</div>
  <div class="box">baz</div>
</div>
.container {
  display: flex;
  gap: 50px;

  .box {
    width: 200px;
    height: 200px;
    background-color: orange;

    &:nth-of-type(1)::after {
      content: "";
      width: 50px;
      height: 50px;
      background-color: blueviolet;
    }
    &:nth-of-type(2):after {
      content: "wow!";
      width: 50px;
      height: 50px;
      background-color: blueviolet;
    }
    &:nth-of-type(3):after {
      content: "";
      display: block;
      width: 50px;
      height: 50px;
      background-color: blueviolet;
    }
  }
}

Pseudo element after

  • ์ฒซ ๋ฒˆ์งธ box ์˜ after ๊ฐ€์ƒ ์—˜๋ฆฌ๋จผํŠธ๋Š” ์ธ๋ผ์ธ ์—˜๋ฆฌ๋จผํŠธ์— width, height ๋ฅผ ์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ฌด๋Ÿฐ ํšจ๊ณผ๋„ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • ๋‘ ๋ฒˆ์งธ box ์˜ after ๊ฐ€์ƒ ์—˜๋ฆฌ๋จผํŠธ ์—ญ์‹œ ์ธ๋ผ์ธ ์—˜๋ฆฌ๋จผํŠธ์ด๋ฏ€๋กœ width, height ๋Š” ๋ฌด์‹œ๋˜๋‚˜, ์ž…๋ ฅ๋œ content ์˜์—ญ ๋งŒํผ ํฌ๊ธฐ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์–ด ๊ธ€์ž๊ฐ€ ํฌํ•จ๋œ ์˜์—ญ ๋งŒํผ ์ ์šฉ๋œ๋‹ค.
  • ์„ธ ๋ฒˆ์งธ box ์˜ after ๊ฐ€์ƒ ์—˜๋ฆฌ๋จผํŠธ๋Š” ์•„๋ฌด๋Ÿฐ ๊ธ€์ž๋กœ ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์ง€๋งŒ, display: block์œผ๋กœ ๋ธ”๋Ÿญ ์—˜๋ฆฌ๋จผํŠธ๋กœ ์†์„ฑ์„ ๋ณ€๊ฒฝํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— content ์˜ ์•„๋ž˜ ์ƒˆ ๋ธ”๋Ÿญ์„ ๊ฐ–๊ณ , ์ฃผ์–ด์ง„ width, height ๋งŒํผ ํšจ๊ณผ๊ฐ€ ์ ์šฉ๋œ๋‹ค.

5. Attribute Selectors

-

<input type="text" data-fruits-apple="apple" />
<input type="password" />
<input type="text"  disabled />
[data-fruits-apple] {
  background-color: lightgreen;
}

input[type="password"] {
  background-color: lightsalmon;
}

input[disabled] {
  background-color: lightskyblue;
}

[type], [disabled]์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋‚˜ ๋„ˆ๋ฌด ๋งŽ์€ ๋ฒ”์œ„๋ฅผ ์„ ํƒํ•œ๋‹ค. ๋‹ค์ˆ˜์˜ ๋Œ€์ƒ์„ ์„ ํƒํ•  ๋•Œ๋Š” class ์†์„ฑ์„ ์‚ฌ์šฉํ•ด์•ผํ•˜๋ฉฐ, ์œ„์™€ ๊ฐ™์ด ์–ด๋–ค ์—˜๋ฆฌ๋จผํŠธ ์ค‘ ํŠน์ • ์†์„ฑ์„ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ [data-fruits-apple]์™€ ๊ฐ™์ด ๊ธฐ๋ณธ ์†์„ฑ์ด ์•„๋‹Œ ํŠน์ • ์†์„ฑ์„ ์„ ํƒํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.


3. CSS Inheritances ๐Ÿ‘ฉโ€

1. Auto Inheritance

CSS ์Šคํƒ€์ผ ์†์„ฑ ์ค‘ ๊ธ€์ž/๋ฌธ์ž์™€ ๊ด€๋ จ๋œ ๋Œ€๋ถ€๋ถ„์˜ ์†์„ฑ(color, font-style, font-weight, font-size, line-height, font-family, text-align, โ€ฆ)์€ ์ปจํ…Œ์ด๋„ˆ ๋‚ด ์ž์‹์—๊ฒŒ ์ƒ์†๋œ๋‹ค(๋ชจ๋“  ๊ธ€์ž/๋ฌธ์ž ์†์„ฑ์ด ์ƒ์†๋˜๋Š” ๊ฒƒ์€ ์•„๋‹˜).

2. Force Inheritance

<div class="parent">
  <div class="child">
    <div class="descendent"></div>
  </div>
</div>
.parent {
  position: relative;
  width: 500px;
  height: 200px;
  background-color: red;
}

.child {
  width: 450px;
  height: 100%;
  margin: 0 auto;
  background-color: lightgreen;
}

.descendent {
  width: 400px;
  height: inherit;
  margin: inherit;
  background-color: blueviolet;
}

CSS Inheritance 1

๋„ˆ๋น„๋‚˜ ๋†’์ด๊ฐ™์€ ๊ฒฝ์šฐ ๋Œ€๋ถ€๋ถ„ ๋ถ€๋ชจ์˜ ๊ฐ’์„ ์ƒ์† ๋ฐ›์•„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์œ ๋ฆฌํ•  ๊ฒฝ์šฐ 100%๋ผ๋Š” ๊ฐ’์„ ์ฃผ์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ background-color, margin, padding๊ณผ ๊ฐ™์€ ์†์„ฑ์€ ์ด๋Ÿฌํ•œ ๊ฐ’์„ ์„ ํƒํ•  ์ˆ˜ ์—†๋‹ค. ์ด๋Ÿฐ ์†์„ฑ ์—ญ์‹œ ๊ฐ’์œผ๋กœ inherit์„ ์ฃผ๋ฉด ๊ฐ•์ œ ์ƒ์†์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

3. CSS Specificity

๋™์ผ CSS ๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ ์„ ์–ธ๋œ ๊ฒฝ์šฐ, ์ ์šฉ ์šฐ์„ ์ˆœ์œ„์— ๋”ฐ๋ผ ์‹ค์ œ ์ ์šฉ๋˜๋Š” ์†์„ฑ๊ฐ’์ด ์ •ํ•ด์ง„๋‹ค.

  1. ์šฐ์„  ์ˆœ์œ„๊ฐ€ ๋†’์€ ์„ ์–ธ์ด ์ ์šฉ๋œ๋‹ค.
  2. ๋™์ผ ์šฐ์„ ์ˆœ์œ„ ๋‚ด์—์„œ๋Š” ๋งˆ์ง€๋ง‰์— ํ•ด์„๋œ ์„ ์–ธ์ด ์ ์šฉ๋œ๋‹ค.

Inheritance > Universal(*) > Type(div) > Class > ID > Inline > !important ์ˆœ์„œ๋กœ ์ ์šฉ๋œ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ CSS ์šฐ์„  ์ˆœ์œ„ ๊ณ„์‚ฐ์— ์œ ์˜ํ•ด์•ผํ•œ๋‹ค.

.hello {
  color: red;
}

.hello {
  color: green;
}

๋™์ผ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ์„ ์–ธ๋˜์—ˆ๊ณ , ๋…น์ƒ‰์ด ๋‚˜์ค‘์— ํ•ด์„๋˜๋ฏ€๋กœ ๊ธ€์ž๋Š” ๋…น์ƒ‰์ด ๋œ๋‹ค.

div.hello {
  color: red;
}

.hello {
  color: green;
}

๊ฐ™์€ Class ๋ ˆ๋ฒจ์˜ CSS ์ง€๋งŒ div.hello๋ผ๋Š” ๋” specific ํ•œ ์„ ํƒ์ž๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ธ€์ž๋Š” ๋นจ๊ฐ„์ƒ‰์ด ๋œ๋‹ค.

div .hello {
  color: red;
}

.hello {
  color: green;
}

div ์ด๋ฉด์„œ .hello์—ฌ์•ผ ํ•˜๋Š” div.hello์™€ ๋‹ฌ๋ฆฌ div ํ•˜์œ„์— .hello๋Š” ๊ฐ™์€ ๋ ˆ๋ฒจ์— ์กด์žฌํ•˜๋Š” .hello์™€ ์šฐ์„  ์ˆœ์œ„๊ฐ€ ๊ฐ™๋‹ค. ๋”ฐ๋ผ์„œ ๋™์ผ ์šฐ์„ ์ˆœ์œ„ ์ค‘ ๋…น์ƒ‰์ด ๋‚˜์ค‘์— ํ•ด์„๋˜๋ฏ€๋กœ ๊ธ€์ž๋Š” ๋…น์ƒ‰์ด ๋œ๋‹ค.


4. CSS Attributes ๐Ÿ‘ฉโ€

1. Box Model

1 ) Box Model

HTML ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ Box Model์„ ์‚ฌ์šฉํ•œ๋‹ค. ์ดˆ์ฐฝ๊ธฐ ์›น์€ ์›Œ๋“œ ๋ฌธ์„œ์™€ ํฌ๊ฒŒ ๋‹ค๋ฅด์ง€ ์•Š์•˜๋‹ค. ๊ธ€๊ณผ ์‚ฌ์ง„ ๊ธ€๊ณผ ์‚ฌ์ง„โ€ฆ ๋”ฐ๋ผ์„œ ์ธ๋ผ์ธ ์†์„ฑ๊ณผ ๋ธ”๋Ÿญ ์†์„ฑ ์—˜๋ฆฌ๋จผํŠธ์˜ ๋ฐ•์Šค๋ฅผ ์Œ“์•„ ๋‚˜์•„๊ฐ€๋Š” ๊ณผ์ •์˜ ์—ฐ์†์ด๋‹ค.

2 ) width, height

  • auto: default
  • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.

๊ธฐ๋ณธ๊ฐ’ auto์ผ ๋•Œ

  • ๋ฐ•์Šค ์—˜๋ฆฌ๋จผํŠธ: width ๋Š” ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ๋งŒํผ ๋Š˜์–ด๋‚˜๊ณ , height ๋Š” content ํฌ๊ธฐ ๋งŒํผ ์ค„์–ด๋“ ๋‹ค.
  • ์ธ๋ผ์ธ ์—˜๋ฆฌ๋จผํŠธ: width ์™€ height ๋Š” content ํฌ๊ธฐ ๋งŒํผ ์ค„์–ด๋“ ๋‹ค.

์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ๋ช…์‹œ์ ์ธ width, height ๊ฐ’์„ ๊ฐ€์ง€๋ ค๋ฉด

๊ฐ€ ๋˜์–ด์•ผ ํ•œ๋‹ค.

3 ) max-โœฑ

max-height, max-width ๋Š” width, height ์˜ !important ๋ณด๋‹ค๋„ ๋†’์€ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ–๋Š”๋‹ค.

  • none: default, ์ œํ•œ ์—†์Œ.
  • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
  • auto: auto ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ–์ง€ ๋ชป ํ•œ๋‹ค.

4 ) min-โœฑ

min-height, min-width ๋Š” width, height ์˜ !important ๋ณด๋‹ค๋„ ๋†’์€ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ–๋Š”๋‹ค.

  • 0: default, ์ œํ•œ ์—†์Œ.
  • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
  • auto: auto ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ–์ง€ ๋ชป ํ•œ๋‹ค.
<div class="parent">
  <div class="child"></div>
</div>
.parent {
  width: 300px;
  height: 200px;
  background-color: royalblue;
}

.child {
  height: 100px;
  background: orange;
}

๊ธฐ๋ณธ๊ฐ’์œผ๋กœ min-width ๋Š” 0, max-width ๋Š” none, width ๋Š” auto๋ฅผ ๊ฐ–๋Š”๋‹ค. ๋ธ”๋Ÿญ ์—˜๋ฆฌ๋จผํŠธ์ด๋ฏ€๋กœ ๋ถ€๋ชจ์˜ ํฌ๊ธฐ ๋งŒํผ ๋Š˜์–ด๋‚œ๋‹ค.

CSS width 1


.child {
  max-width: 200px;
  height: 100px;
  background: orange;
}

max-width ๊ฐ€ ์ œํ•œ๋จ์— ๋”ฐ๋ผ ๋„ˆ๋น„๊ฐ€ 200์œผ๋กœ ์ œํ•œ๋œ๋‹ค.

CSS width 2


.child {
  width: 500px !important;
  max-width: 200px;
  height: 100px;
  background: orange;
}
.child {
  min-width: 200px;
  width: 100px !important;
  height: 100px;
  background: orange;
}

CSS width 2

์œ„ ๋‘ ์ผ€์ด์Šค๋Š” ๋ชจ๋‘ ๋„ˆ๋น„๊ฐ€ 200์ด ๋œ๋‹ค. width ์— !important๋ฅผ ์ฃผ๋”๋ผ๋„ max-width, min-width์˜ ์šฐ์„  ์ˆœ์œ„๊ฐ€ ๋” ๋†’๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

2. Units

  • px: ํ”ฝ์…€. ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ ์ ˆ๋Œ€ ๋‹จ์œ„๋กœ ์ธ์‹ํ•˜๋Š” ๋ฐ, ๋””๋ฐ”์ด์Šค ์ƒํ™ฉ์— ๋”ฐ๋ผ์„œ ํ”ฝ์…€์— ๋Œ€ํ•œ ๊ธฐ์ค€์ด ์กฐ๊ธˆ์”ฉ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ์ง€๋ฉด ์ƒ๋Œ€ ๋‹จ์œ„๋กœ ๋ณด๋Š” ํŽธ์ด ๋งž๋‹ค. ์•„๋ฌด๋Ÿฐ ์„ค์ •์„ ํ•˜์ง€ ์•Š์•˜์„ ๋•Œ, ์—˜๋ฆฌ๋จผํŠธ์˜ font-size ๊ธฐ๋ณธ๊ฐ’์€ 16px์ด๋‹ค.
  • %: ์ƒ๋Œ€์  ๋ฐฑ๋ถ„์œจ.
  • em: ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ธ€๊ผด ํฌ๊ธฐ์— ๋Œ€ํ•œ ๋น„์œจ. ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ธ€๊ผด ํฌ๊ธฐ๊ฐ€ 10px์ด๋ฉด, 1em์€ 10px์ด ๋œ๋‹ค. font-size ๊ฐ€ ์ƒ์†์— ์˜ํ•ด ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์ฃผ์˜ํ•ด ์‚ฌ์šฉํ•ด์•ผํ•˜๋ฉฐ ๊ด€๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
  • rem: root ์—˜๋ฆฌ๋จผํŠธ(=html)์˜ ๊ธ€๊ผด ํฌ๊ธฐ, ๊ฐ ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ธ€๊ผด ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•˜๋Š” em๊ณผ ๋‹ค๋ฅด๊ฒŒ html ์˜ ๊ธ€๊ผด ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•œ๋‹ค.
  • vw: viewport ๊ฐ€๋กœ ๋„ˆ๋น„์˜ ๋ฐฑ๋ถ„์œจ.
  • vh: viewport ์„ธ๋กœ ๋†’์ด์˜ ๋ฐฑ๋ถ„์œจ.
.parent {
  width: 300px;
  height: 200px;
  background-color: royalblue;
}

.child {
  width: 20em;
  height: 50%;
  background: orange;
}

๋ณ„๋„์˜ font-size ์„ค์ •์„ ํ•˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ, ๊ธฐ๋ณธ font-size ๋Š” 16px์ด๊ณ , .child์˜ 1em์€ 16px์ด๋‹ค. ๊ทธ๋Ÿฐ๋ฐ 20em์„ ์ฃผ์—ˆ์œผ๋ฏ€๋กœ, ๋„ˆ๋น„๋Š” 320px์ด ๋œ๋‹ค.

CSS unit 1


.parent {
  width: 300px;
  height: 200px;
  background-color: royalblue;
  font-size: 10px;
}

๋งŒ์•ฝ, ๋ถ€๋ชจ์˜ font-size ๋ฅผ 10px๋กœ ์ฃผ๋ฉด ์ƒ์†๋˜์–ด .child์˜ 1em์€ 10px์ด ๋˜๊ณ , 20em์€ 200px์ด ๋œ๋‹ค.

CSS unit 2


.child {
  width: 20rem;
  height: 50%;
  background: orange;
}

CSS unit 1

em์€ ๋ถ€๋ชจ ๋˜๋Š” ์กฐ์ƒ์˜ font-size ๊ฐ€ ๋‹ฌ๋ผ์ง€๋ฉด, ์ƒ์†์— ์˜ํ•ด ํฌ๊ธฐ๊ฐ€ ๋ณ€ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ˜ผ๋ž€์Šค๋Ÿฌ์šด ๋‹จ์œ„๊ฐ€ ๋  ์ˆ˜ ์žˆ์–ด ๊ด€๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

๋ฐ˜๋ฉด rem์€ ํ•ญ์ƒ root ์—˜๋ฆฌ๋จผํŠธ์ธ html ์˜ font-size ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ƒ์†์— ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์•„ ์•ˆ์ •์ ์ด๋ฉฐ, html ์˜ font-size ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ ๋งŒ์œผ๋กœ ์›น ์ „์ฒด์˜ ํฌ๊ธฐ๋ฅผ ๋น„์œจ๋กœ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์„ ๊ฐ–๋Š”๋‹ค.

3. Margin

์—˜๋ฆฌ๋จผํŠธ์˜ ์™ธ๋ถ€ ์—ฌ๋ฐฑ์„ ์ง€์ •ํ•˜๋Š” ๋‹จ์ถ• ์†์„ฑ.

  • 0: default, ์™ธ๋ถ€ ์—ฌ๋ฐฑ ์—†์Œ.
  • auto: ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์—ฌ๋ฐฑ์„ ๊ณ„์‚ฐ(๋ธ”๋Ÿญ ์—˜๋ฆฌ๋จผํŠธ & ๊ฐ€๋กœ ๋„ˆ๋น„๊ฐ€ ์žˆ๋Š” ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ฐ€์šด๋ฐ ์ •๋ ฌ์— ํ™œ์šฉ)(์„ธ๋กœ ์ •๋ ฌ์€ ์•ˆ ๋จ).
  • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค(์Œ์ˆ˜๊ฐ’ ์‚ฌ์šฉ ๊ฐ€๋Šฅ).
  • %: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ฐ€๋กœ ๋„ˆ๋น„์— ๋Œ€ํ•œ ๋น„์œจ๋กœ ์ง€์ •ํ•˜์ง€๋งŒ ์‹ค์ œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐฉ์‹์€ ์•„๋‹ˆ๋‹ค.

margin-collapsing์ด ๋ฐœ์ƒ๋œ๋‹ค.

4. Padding

์—˜๋ฆฌ๋จผํŠธ์˜ ๋‚ด๋ถ€ ์—ฌ๋ฐฑ์„ ์ง€์ •ํ•˜๋Š” ๋‹จ์ถ• ์†์„ฑ.

  • 0: default, ๋‚ด๋ถ€ ์—ฌ๋ฐฑ ์—†์Œ.
  • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
  • %: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ฐ€๋กœ ๋„ˆ๋น„์— ๋Œ€ํ•œ ๋น„์œจ๋กœ ์ง€์ •ํ•œ๋‹ค.

์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ๊ฐ€ ์ปค์ง„๋‹ค.


Margin ๊ณผ Padding ๋ชจ๋‘ %๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ฐ€๋กœ ๋„ˆ๋น„์— ๋Œ€ํ•œ ๋น„์œจ๋กœ ์ง€์ •ํ•œ๋‹ค๊ณ  ํ–ˆ๋‹ค. ์ด ๋ถ€๋ถ„์—์„œ ์ฃผ์˜ํ•ด์•ผ ํ•  ๊ฒƒ์ด left์™€ right๋Š” ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ width์— ์˜ํ–ฅ์„ ๋ฐ›๊ณ , top๊ณผ bottom์€ ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ height์— ์˜ํ–ฅ์„ ๋ฐ›์„ ๊ฒƒ ๊ฐ™์ง€๋งŒ, ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ height๊ฐ€ 0์œผ๋กœ ์กด์žฌํ•˜์ง€ ์•Š๋“ , ๋งค์šฐ ํฐ ๊ฐ’์„ ๊ฐ€์ง€๋“  ์ƒ๊ด€ ์—†์ด top, right, bottom, left ๋ชจ๋‘ ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ๊ฐ€๋กœ ๋„ˆ๋น„์— ๋Œ€ํ•œ ๋น„์œจ์„ ์ฐธ์กฐํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด

<div class="container">
  <div class="item"></div>
</div>

์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋ฅผ ์ •์˜ํ•˜๊ณ , ๋‹ค์Œ๊ณผ ๊ฐ™์ด CSS ๋ฅผ ์ •์˜ํ•˜๋ฉด, ๋†’์ด๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์•„๋„ ํ•ญ์ƒ 16:9 ๋น„์œจ์˜ ๊ณต๊ฐ„์ด ์ƒ๊ฒจ๋‚œ๋‹ค.

.container {
  width: 800px;
  background-color: grey;
  
  .item {
    padding-top: 56.25%;  /* 16:9 */
  }
}

๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด ๋””์ž์ธ์„ ์œ„ํ•ด ๋ถˆํ•„์š”ํ•œ item ์ด๋ผ๋Š” ๊ตฌ์กฐ๋ฅผ ์ถ”๊ฐ€๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  Pseudo-element before ๋˜๋Š” after๋ฅผ ์‚ฌ์šฉํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์˜์—ญ์„ ์„ค์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

.container {
  width: 800px;
  background-color: grey;
  
  &::before {
    content: "";
    display: block;
    padding-top: 56.25%;  /* 16:9 */
  }
}

5. border

์—˜๋ฆฌ๋จผํŠธ์˜ ํ…Œ๋‘๋ฆฌ ์„ ์„ ์ง€์ •ํ•˜๋Š” ๋‹จ์ถ• ์†์„ฑ.

  • border-width
    • medium: default, ์ค‘๊ฐ„ ๋‘๊ป˜(medium, thin, thick๋Š” ๋ธŒ๋ผ์šฐ์ €์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๊ตฌํ˜„๋  ์ˆ˜ ์žˆ์–ด ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค).
    • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
  • border-style
    • none: default, ์„  ์—†์Œ.
    • solid: ์‹ค์„ .
    • dashed: ํŒŒ์„ (ํ•œ๊ตญ์—์„œ ์ ์„ ์ด๋ผ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์€ ์˜์–ด๋กœ๋Š” dotted ๊ฐ€ ์•„๋‹ˆ๋ผ dashed ๋‹ค).
    • ๊ทธ ์™ธ dotted, double, groove, ridge, inset, outset ์€ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • border-color
    • black: default.
    • ์ƒ‰์ƒ๊ฐ’: CSS ์ƒ‰์ƒ๊ฐ’์„ ์‚ฌ์šฉํ•œ๋‹ค(red, tomato ์™€ ๊ฐ™์€ ๊ฐ’์€ ๋ธŒ๋ผ์šฐ์ €๋งˆ๋‹ค ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์–ด ๊ถŒ์žฅ๋˜์ง€ ์•Š๋Š”๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ #์„ ์‚ฌ์šฉํ•œ HEX ์ƒ‰์ƒ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, RGB ๋˜๋Š” RGBA ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค).
    • transparent: ํˆฌ๋ช…ํ•œ border ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.

border: ๋‘๊ป˜, ์ข…๋ฅ˜, ์ƒ‰์ƒ; ์œผ๋กœ ์ •์˜ํ•œ๋‹ค(๊ธฐ๋ณธ๊ฐ’์€ medium none black).

์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ๊ฐ€ ์ปค์ง„๋‹ค.

6. border-radius

์—˜๋ฆฌ๋จผํŠธ์˜ ๋ชจ์„œ๋ฆฌ๋ฅผ ๋‘ฅ๊ธ€๊ฒŒ ๊นŽ๋Š” ๋‹จ์ถ• ์†์„ฑ.

  • 0: default, ๋ชจ์„œ๋ฆฌ ๊ฐ์ง.
  • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.

๋‹จ์ถ• ์†์„ฑ์€ 10์‹œ ๋ฐฉํ–ฅ๋ถ€ํ„ฐ ์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ ๋Œ๋ฉฐ ์ ์šฉ๋œ๋‹ค(i.e. border-radius: 0 20px 0 0;).

7. box-sizing

์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ ๊ณ„์‚ฐ ๊ธฐ์ค€์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ

  • content-box: default, content ๋กœ ํฌ๊ธฐ ๊ณ„์‚ฐ.
  • border-box: content + padding + border๋กœ ํฌ๊ธฐ ๊ณ„์‚ฐ.
<div class="item"></div>
<div class="item"></div>
.item {
  width: 100px;
  height: 100px;
  background-color: orange;
}
  • content-box
.item:first-child {
  border: 4px solid red;
  padding: 10px;
}

Box-Sizing Content-Box

content ์— padding, border ๋ฅผ ํ•ฉํ•œ ์˜์—ญ์˜ ํฌ๊ธฐ๋Š” 100px(content) + 2 * 10px(padding) + 2 * 4px(border) = 128px์ด ๋œ๋‹ค.


  • border-box
.item:first-child {
  border: 4px solid red;
  padding: 10px;
  box-sizing: border-box;
}

Box-Sizing Border-Box

content + padding + border ๋ฅผ ํ•ฉํ•œ ์˜์—ญ์˜ ํฌ๊ธฐ๊ฐ€ 100px ์ด๋ฏ€๋กœ 100px = 2 * 10px(padding) + 2 * 4px(border) + ?(content)์—์„œ content ์˜ ํฌ๊ธฐ๋Š” 72px์ด ๋œ๋‹ค.

์œ„์—์„œ padding ๊ณผ border ๋ฅผ ์ฃผ๋ฉด ์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ๊ฐ€ ์ปค์ง„๋‹ค๊ณ  ํ–ˆ๋‹ค. ์ด๊ฒƒ์€ box-sizing์ด ๊ธฐ๋ณธ๊ฐ’์ธ content-box์ผ ๋•Œ ํ–‰๋™์ด๋‹ค. ์œ„์™€ ๊ฐ™์ด border-box๋กœ ์†์„ฑ์„ ๋ณ€๊ฒฝํ•˜๋ฉด, width ๊ฐ’์ด box ์˜ ํฌ๊ธฐ๊ฐ€ ๋˜๋ฏ€๋กœ, padding ๊ณผ border ๋ฅผ ์ ์šฉํ•œ ๋งŒํผ ์—ญ์œผ๋กœ content ์˜ ํฌ๊ธฐ๊ฐ€ ์ค„์–ด๋“ ๋‹ค.

8. overflow

์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ ์ด์ƒ์œผ๋กœ content ๊ฐ€ ๋„˜์ณค์„ ๋•Œ, ๋ณด์—ฌ์ง์„ ์ง€์ •ํ•˜๋Š” ๋‹จ์ถ• ์†์„ฑ์œผ๋กœ ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์— ์ ์šฉํ•˜๋Š” ์†์„ฑ.

  • visiable: default, ๋„˜์นœ ๋‚ด์šฉ์„ ๊ทธ๋Œ€๋กœ ๋ณด์—ฌ์คŒ.
  • hidden: ๋„˜์นœ ๋‚ด์šฉ์„ ์ž˜๋ผ๋ƒ„.
  • scroll: ๋„˜์นœ ๋‚ด์šฉ์„ ์ž˜๋ผ๋ƒ„. ์Šคํฌ๋กค๋ฐ” ์ƒ์„ฑ(๋ธŒ๋ผ์šฐ์ €์— ๋”ฐ๋ผ ๊ฐ€๋กœ ์Šคํฌ๋กค๋งŒ ์ƒ๊ฒจ์•ผ ํ•˜๋Š”๋ฐ ์„ธ๋กœ ์Šคํฌ๋กค๋ฐ”๊นŒ์ง€ ๊ฐ™์ด ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์–ด ํ•„์š”์‹œ auto ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค).
  • auto: ๋„˜์นœ ๋‚ด์šฉ์ด ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ์ž˜๋ž˜๋‚ด๊ณ  ์Šคํฌ๋กค๋ฐ” ์ƒ์„ฑ.

9. display

์—˜๋ฆฌ๋จผํŠธ์˜ ํ™”๋ฉด ์ถœ๋ ฅ(๋ณด์—ฌ์ง) ํŠน์„ฑ์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • Type ์— ๊ธฐ๋ณธ์œผ๋กœ ์ง€์ •๋œ ๊ฐ’
    • block: default, ์ƒ์ž(๋ ˆ์ด์•„์›ƒ) ์—˜๋ฆฌ๋จผํŠธ. i.e. div
    • inline: default, ๊ธ€์ž ์—˜๋ฆฌ๋จผํŠธ. i.e. span
    • inline-block: default, ์ธ๋ผ์ธ ์—˜๋ฆฌ๋จผํŠธ์ง€๋งŒ width, height ์†์„ฑ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋“ฑ ์ผ๋ถ€ ๋ธ”๋Ÿญ ์—˜๋ฆฌ๋จผํŠธ ์†์„ฑ์„ ์ถ”๊ฐ€๋กœ ๊ฐ–๋Š”๋‹ค. i.e. img, button, input, label, textarea, select ๋“ฑ
  • Type ์— ๊ธฐ๋ณธ์œผ๋กœ ์ง€์ •๋˜์ง€ ์•Š๋Š” ๊ฐ’
    • flex: ํ”Œ๋ ‰์Šค ๋ฐ•์Šค(1์ฐจ์› ๋ ˆ์ด์•„์›ƒ).
    • grid: ๊ทธ๋ฆฌ๋“œ(2์ฐจ์› ๋ ˆ์ด์•„์›ƒ).
    • none: ๋ณด์—ฌ์ง ํŠน์„ฑ ์—†์Œ. ํ™”๋ฉด์—์„œ ์‚ฌ๋ผ์ง.
    • table, table-row, table-cell ๋“ฑ ๋‹ค์–‘ํ•œ ์†์„ฑ๊ฐ’์ด ์กด์žฌํ•œ๋‹ค.

10. opacity

์—˜๋ฆฌ๋จผํŠธ์˜ ํˆฌ๋ช…๋„๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • 1: default, ๋ถˆํˆฌ๋ช….
  • 0..<1: 1์„ 100์œผ๋กœ ๋ฐฑ๋ถ„์œจ๋กœ ํ™˜์‚ฐ๋˜์–ด๋Š” ๊ฐ’.

11. font

๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ธฐ๋ณธ CSS ๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๊ธฐ ์œ„ํ•ด ์ง์ ‘ ์ •์˜ํ•œ reset ์ด ์•„๋‹Œ reset.css ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด h1์˜ ํฌ๊ธฐ์™€ ๊ฐ™์€ ์Šคํƒ€์ผ๋„ ์ œ๊ฑฐ๋˜์–ด ํ•„์š”์‹œ ์ •์˜ํ•ด์ค˜์•ผํ•œ๋‹ค.

  • font-style
    • normal: default, ๊ธฐ์šธ๊ธฐ ์—†์Œ.
    • italic: ์ดํ…”๋ฆญ์ฒด.
    • oblique: ๋ช…ํ™•ํ•˜๊ฒŒ ๊ธฐ์šธ์ž„์ด๋ผ๋Š” ์Šคํƒ€์ผ์ด์ง€๋งŒ ์ผ๋ฐ˜์ ์œผ๋กœ italic ์„ ์‚ฌ์šฉํ•จ.
  • font-weight
    • normal, 400: default, ๊ธฐ๋ณธ ๋‘๊ป˜
    • bold, 700: ๋‘๊ป๊ฒŒ(์ผ๋ฐ˜์ ์œผ๋กœ 700์ด bold ๋ฅผ ์˜๋ฏธํ•˜์ง€๋งŒ ํฐํŠธ๋งˆ๋‹ค ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค).
    • bolder: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ๋ณด๋‹ค ๋” ๋‘๊ป๊ฒŒ(์ƒ์†์— ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์œผ๋กœ ์ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค).
    • lighter: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ๋ณด๋‹ค ๋” ์–‡๊ฒŒ(์ƒ์†์— ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์œผ๋กœ ์ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค).
    • 100...900: 100 ๋‹จ์œ„ ์ˆซ์ž 9๊ฐœ๋กœ ํ‘œํ˜„ ๊ฐ€๋Šฅ.
  • font-size
    • 16px: default.
    • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
    • %: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ํฐํŠธ ํฌ๊ธฐ์— ๋Œ€ํ•œ ๋น„์œจ๋กœ ์ง€์ •ํ•œ๋‹ค.
    • larger: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ๋ณด๋‹ค ๋” ํฌ๊ฒŒ(์ƒ์†์— ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์œผ๋กœ ์ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค).
    • smaller: ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ๋ณด๋‹ค ๋” ์ž‘๊ฒŒ(์ƒ์†์— ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋ฐ˜์ ์œผ๋กœ ์ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค).
    • xx-small...xx-large: 7๋‹จ๊ณ„๋กœ ํฌ๊ธฐ ํ‘œํ˜„ ๊ฐ€๋Šฅ.
  • line-height: ํ•œ ์ค„์˜ ๋†’์ด, ํ–‰๊ฐ„๊ณผ ์œ ์‚ฌ(์™„์ „ํžˆ ์ผ์น˜ํ•˜๋Š” ๊ฐœ๋… ์•„๋‹˜).
    ๊ณผ๊ฑฐ flex ๊ฐ€ ์—†๋˜ ์‹œ์ ˆ์—๋Š” ์ˆ˜์ง ์ •๋ ฌ์„ ์‹œํ‚ค๊ธฐ ์œ„ํ•ด line-height ๋ฅผ ์‚ฌ์šฉํ•˜๊ณค ํ–ˆ๋Š”๋ฐ ์ง€๊ธˆ์€ flex ๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ •๋ง line-height ๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ชฉ์ ์œผ๋กœ๋งŒ ์‚ฌ์šฉํ•œ๋‹ค.
    • normal, 1: default.
    • ์ˆซ์ž: ์—˜๋ฆฌ๋จผํŠธ ๊ธ€๊ผด ํฌ๊ธฐ์˜ ๋ฐฐ์ˆ˜๋กœ ์ง€์ •.
    • ๋‹จ์œ„๊ฐ’: px, em, vw ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
    • %: ์—˜๋ฆฌ๋จผํŠธ ๊ธ€๊ผด ํฌ๊ธฐ์˜ ๋น„์œจ๋กœ ์ง€์ •(์ˆซ์ž๋งŒ์œผ๋กœ ํ‘œํ˜„ ๊ฐ€๋Šฅ).

    Line-Height

  • font-family
    • Font, font-family: Arial, "Helvetica Neue", sans-serif; ์™€ ๊ฐ™์ด ์ž‘์„ฑํ•œ๋‹ค.
    • ํฐํŠธ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋Œ€๋ฌธ์ž๋กœ ์ž‘์„ฑํ•˜๊ณ , ๊ณต๋ฐฑ์ด๋‚˜ ํŠน์ˆ˜๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜๋ฉด ๋ฐ˜๋“œ์‹œ " "๋กœ ๋ฌถ์–ด์ค€๋‹ค(์‹ค์ œ๋กœ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹˜).
    • ๋งˆ์ง€๋ง‰์œผ๋กœ ํฐํŠธ ๊ณ„์—ด(serif, sans-serif, monospace, cursive, fantasy)๋ฅผ ๋ฐ˜๋“œ์‹œ ์ž‘์„ฑํ•œ๋‹ค.

    Font-Family


์œ„ ์†์„ฑ๋“ค์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋”ฐ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•˜์ง€๋งŒ, ์—ฌ๋Ÿฌ ์†์„ฑ์„ ๋ชจ๋‘ ์„ ์–ธํ•  ๊ฒฝ์šฐ ๋‹จ์ถ• ์†์„ฑ์œผ๋กœ ์ •์˜ํ•˜๊ธฐ๋„ ํ•œ๋‹ค.

.nanum-gothic-regular {
  font-weight: 400;
  font-style: normal;
  font-size: 16px;
  line-height: 1.5;
  font-family: "Nanum Gothic", sans-serif;
}
.nanum-gothic-regular {
  font: 400 normal 16px/1.5 "Nanum Gothic", sans-serif;
}


  • text-align
    • left: default, ์™ผ์ชฝ ์ •๋ ฌ.
    • right: ์˜ค๋ฅธ์ชฝ ์ •๋ ฌ.
    • center: ๊ฐ€์šด๋ฐ ์ •๋ ฌ.
    • justify: ์–‘์ชฝ ์ •๋ ฌ. ์‚ฌ์‹ค์ƒ ์™ผ์ชฝ ์ •๋ ฌ๊ณผ ๊ฐ™๋‹ค.
  • text-decoration
    • none: default, ์žฅ์‹ ์—†์Œ.
    • underline: ๋ฐ‘์ค„(a ํƒœ๊ทธ์˜ ๊ฒฝ์šฐ๋Š” underline ์ด ๊ธฐ๋ณธ๊ฐ’, ์ผ๋ฐ˜์ ์œผ๋กœ reset ์œผ๋กœ ์ œ๊ฑฐํ•œ๋‹ค).
    • overline: ์œ—์ค„.
    • line-through: ์ค‘์•™์„ . HTML ์˜ del, ins ํƒœ๊ทธ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜๊ณค ํ•œ๋‹ค.
  • text-indent
  • 0: default, ๋“ค์—ฌ์“ฐ๊ธฐ/๋‚ด์–ด์“ฐ๊ธฐ ์—†์Œ.
  • ์–‘์ˆ˜: ๋“ค์—ฌ์“ฐ๊ธฐ.
  • ์Œ์ˆ˜: ๋‚ด์–ด์“ฐ๊ธฐ.
  • -9999px: img ์—˜๋ฆฌ๋จผํŠธ๋Š” alt ์†์„ฑ์ด ์žˆ๋‹ค. ํ•˜์ง€๋งŒ img์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ์—˜๋ฆฌ๋จผํŠธ์— background-image๋ฅผ ์‚ฌ์šฉํ•ด ์ด๋ฏธ์ง€๋ฅผ ์ œ๊ณตํ•˜๊ณ , alternative text ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด text-indent๋กœ ํ…์ŠคํŠธ๋ฅผ ์ถฉ๋ถ„ํžˆ ๋‚ด์–ด์“ฐ๊ธฐ ํ•ด ํ™”๋ฉด์— ๋ณด์ด์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋•Œ -9999px ์„ ์‚ฌ์šฉํ•œ๋‹ค(์ž์‹์—๊ฒŒ ์ƒ์†๋˜๋ฏ€๋กœ, ๋ถ€๋ชจ์—๊ฒŒ ์ ์šฉํ•ด ํ•˜์œ„ ๋ชจ๋“  ์—˜๋ฆฌ๋จผํŠธ์˜ ํ…์ŠคํŠธ๋ฅผ alternative text ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์ „๋ถ€ background-image๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค).
  • %: ์—˜๋ฆฌ๋จผํŠธ์˜ *๊ฐ€๋กœ ๋„ˆ๋น„**์— ๋Œ€ํ•œ ๋น„์œจ๋กœ ์ง€์ •ํ•˜์ง€๋งŒ ์‹ค์ œ ์‚ฌ์šฉ๋˜๋Š” ๋ฐฉ์‹์€ ์•„๋‹ˆ๋‹ค.

12. background

HTML ์€ Box Model์„ ์ฑ„ํƒํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ์—˜๋ฆฌ๋จผํŠธ์˜ ๋ฐฐ๊ฒฝ ์ •๋ณด๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • background-color
    • transparent: default, ํˆฌ๋ช…ํ•จ.
    • ์ƒ‰์ƒ๊ฐ’: CSS ์ƒ‰์ƒ๊ฐ’์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • background-image
    • none: default, ์ด๋ฏธ์ง€ ์—†์Œ.
    • url("path"): ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ.
  • background-size
    • auto: default, ์ด๋ฏธ์ง€์˜ ์‹ค์ œ ํฌ๊ธฐ.
    • ๋‹จ์œ„๊ฐ’: px, em, rem ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.
    • cover: ๋น„์œจ์„ ์œ ์ง€, ์—˜๋ฆฌ๋จผํŠธ์˜ ๋” ๋„’์€ ๋„ˆ๋น„์— ๋งž์ถ˜๋‹ค.
    • contain: ๋น„์œจ์„ ์œ ์ง€, ์—˜๋ฆฌ๋จผํŠธ์˜ ๋” ์งง์€ ๋„ˆ๋น„์— ๋งž์ถ˜๋‹ค.
  • background-repeat
    • repaet: default, ๋ฐ”๋‘‘ํŒ์‹ ๋ฐ˜๋ณต.
    • repeat-x: X์ถ• ๋ฐ˜๋ณต.
    • repeat-y: Y์ถ• ๋ฐ˜๋ณต.
    • no-repeat: ๋ฐ˜๋ณต ์—†์Œ.
  • background-position
    • 0% 0%: (X์ถ•, Y์ถ•)์˜ ๋ฐฑ๋ถ„์œจ.
    • ๋ฐฉํ–ฅ: top, bottom, left, right, center๋Š” ๋ฌผ๋ก ์ด๊ณ , top right์™€ ๊ฐ™์ด ๋ณตํ•ฉ์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.
    • ๋‹จ์œ„๊ฐ’: (X์ถ•, Y์ถ•)์˜ px, em, rem ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.

์ด๋ฏธ์ง€์˜ ์ขŒ์ธก ์ƒ๋‹จ ๋ชจ์„œ๋ฆฌ๋ฅผ ์›์ ์œผ๋กœ ํ•˜๋Š” XY์ถ• 2์ฐจ์› ํ‰๋ฉด์— ์˜ฌ๋ ค๋‘๊ณ , ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์–ผ๋งˆ๋‚˜ X์ถ•, Y์ถ•์œผ๋กœ ํ‰ํ–‰์ด๋™์‹œํ‚ค๋ƒ์— ๋”ฐ๋ผ ์ด๋ฏธ์ง€ ์œ„์น˜๊ฐ€ ๊ฒฐ์ •๋œ๋‹ค.

Background Position 1

์œ„ ์ด๋ฏธ์ง€๋Š” 400px, 400px์˜ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. 100px, 100px๋กœ ์ œํ•œํ•˜๋ฉด ํ•˜๋‚˜์˜ ์‚ฌ๊ฐํ˜•(1๋ฒˆ)๋งŒ ๋ณด์ผ ๊ฒƒ์ด๋‹ค.

<div class="bg-item"></div>
.bg-item {
  width: 100px;
  height: 100px;
  background-image: url("/assets/images/posts/2024-02-03-css-summary/background-position.png");
}


background-position์€ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ํ‰ํ–‰์ด๋™์‹œํ‚จ๋‹ค๊ณ  ํ–ˆ๋‹ค. ์ฆ‰, 7๋ฒˆ์„ ๋ณด์ด๊ฒŒ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, X์ถ•์œผ๋กœ -200px, Y์ถ•์œผ๋กœ -100px ๋งŒํผ ์ด๋™์‹œ์ผœ์•ผ ํ•œ๋‹ค. ์ฆ‰, div๋ผ๋Š” ์˜์—ญ์€ ๊ณ ์ •๋œ ์œ„์น˜์— 100px, 100px๋งŒํผ์˜ ์˜์—ญ์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ๊ทธ ๋’ค์— ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๊ฐ€ -200px, -100px๋งŒํผ ์ด๋™ํ•ด 7๋ฒˆ์ด ๋ณด์ด๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

.bg-item {
  width: 100px;
  height: 100px;
  background-image: url("/assets/images/posts/2024-02-03-css-summary/background-position.png");
  background-position: -200px -100px;
}


๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, ํ˜„์žฌ div์˜ width ์™€ height ๊ฐ€ ๊ฐ๊ฐ 100%์ด๋ฏ€๋กœ, -200%, -100%์™€ ๊ฐ™์ด ๋ฐฑ๋ถ„์œจ์„ ์‚ฌ์šฉํ•ด ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

.bg-item {
  width: 100px;
  height: 100px;
  background-image: url("/assets/images/posts/2024-02-03-css-summary/background-position.png");
  background-position: -200% -100%;
}


  • background-attachment
    • scroll: ์ด๋ฏธ์ง€๊ฐ€ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ™์ด ์Šคํฌ๋กค ๋œ๋‹ค.
    • fixed: ์ด๋ฏธ์ง€๊ฐ€ viewport ์— ๊ณ ์ •. ์Šคํฌ๋กค ๋˜์ง€ ์•Š๋Š”๋‹ค(position fixed ์™€ ์œ ์‚ฌํ•˜๋‹ค).
    • local: ์—˜๋ฆฌ๋จผํŠธ ๋‚ด ์Šคํฌ๋กค ์‹œ ์ด๋ฏธ์ง€๊ฐ€ ๊ฐ™์ด ๋œ๋‹ค.

5. CSS Layout Attributes ๐Ÿ‘ฉโ€

background ์†์„ฑ์—์„œ์˜ background-position์€ ์—˜๋ฆฌ๋จผํŠธ ๋‚ด ์œ„์น˜๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ์ด์—ˆ๋‹ค. ์ด๊ฒƒ์€ ์—˜๋ฆฌ๋จผํŠธ ๋‚ด๋ถ€๋ผ๋Š” ๊ธฐ์ค€์ด ์ •ํ•ด์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ ๊ธฐ์ค€์„ ์„ค์ •ํ•  ํ•„์š” ์—†์ด ์œ„์น˜๋งŒ ์ง€์ •ํ•˜๋ฉด ๋๋‹ค.

ํ•˜์ง€๋งŒ HTML ์—˜๋ฆฌ๋จผํŠธ๋“ค์˜ ์œ„์น˜๋ฅผ ์ง€์ •ํ•  ๋•Œ๋Š” ๋ฐ˜๋“œ์‹œ โ‘  ์œ„์น˜์˜ ๊ธฐ์ค€์„ ์ง€์ •ํ•˜๊ณ , โ‘ก ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด์•ผํ•œ๋‹ค.

1. position

์—˜๋ฆฌ๋จผํŠธ์˜ โ‘  ์œ„์น˜์˜ ๊ธฐ์ค€์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • static: default, ๊ธฐ์ค€ ์—†์Œ.
  • relative: ์—˜๋ฆฌ๋จผํŠธ ์ž์‹ ์„ ๊ธฐ์ค€์ ์œผ๋กœ ์ง€์ •(relative ์— ์˜ํ•ด ์ด๋™ํ•œ ๊ฒƒ์€ Flex - Order ์ฒ˜๋Ÿผ ์‹œ๊ฐ์ ์œผ๋กœ๋งŒ ์ด๋™๋œ ๊ฒƒ์ผ ๋ฟ ์ฒ˜๋Ÿผ ์‹ค์ œ ๋ฐฐ์น˜๊ฐ€ ์ด๋™ํ•œ ๊ฒƒ์€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ˜•์ œ ์—˜๋ฆฌ๋จผํŠธ์˜ ๋ฐฐ์น˜์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค).
  • absolute: ๊ธฐ์ค€์ ์ด ์กด์žฌํ•˜๋Š” ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๊ธฐ์ค€(relative ์™€ ๊ฐ™์ด ๊ธฐ์ค€์ ์ด ์ง€์ •๋œ ๋ถ€๋ชจ๋ฅผ ์ฐพ์•„ ์˜ฌ๋ผ๊ฐ„๋‹ค. ์œ„์น˜ ๊ธฐ์ค€์ ์ด ์—†๋‹ค๋ฉด root ์ธ HTML ๋กœ ์˜ฌ๋ผ๊ฐ„๋‹ค).
  • fixed: viewport(๋ธŒ๋ผ์šฐ์ €)๋ฅผ ๊ธฐ์ค€.
  • sticky: ์Šคํฌ๋กค ์˜์—ญ ๊ธฐ์ค€.

position๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” CSS ์†์„ฑ์€ top, bottom, left, right, z-index ๋“ฑ์ด ์žˆ์œผ๋ฉฐ, ์Œ์ˆ˜๊ฐ’์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

  • auto: default, ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๊ณ„์‚ฐ.
  • ๋‹จ์œ„๊ฐ’: px, em, rem ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.

position์˜ ์†์„ฑ๊ฐ’์œผ๋กœ absolute, fixed๊ฐ€ ์ง€์ •๋œ ์—˜๋ฆฌ๋จผํŠธ๋Š” display ์†์„ฑ์ด block ์œผ๋กœ ๋ณ€๊ฒฝ๋œ๋‹ค. ํ•˜์ง€๋งŒ ์ฃผ์˜ํ•ด์•ผ ํ•  ๊ฒƒ์ด ๊ธฐ๋ณธ์ ์œผ๋กœ block ์—˜๋ฆฌ๋จผํŠธ๋Š” ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์˜ ํฌ๊ธฐ๋งŒํผ width ๊ฐ€ ๋Š˜์–ด๋‚˜์ง€๋งŒ, absolute, fixed ๊ฐ€ ์ง€์ •๋˜๋ฉด inline ์—˜๋ฆฌ๋จผํŠธ์™€ ๊ฐ™์ด width ๊ฐ€ content ํฌ๊ธฐ ๋งŒํผ ์ค„์–ด๋“ ๋‹ค. ๋”ฐ๋ผ์„œ, header์™€ ๊ฐ™์€ ์—˜๋ฆฌ๋จผํŠธ์— fixed๋ฅผ ์ง€์ •ํ•˜๋ฉด์„œ ๋„ˆ๋น„๋ฅผ ๋‹ค ์‚ฌ์šฉํ•˜๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๋ฉด width: 100%;๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •ํ•ด์•ผํ•œ๋‹ค.

<div class="container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
</div>
.container {
  width: 300px;
  background-color: royalblue;
}

.container .item {
  border: 4px dashed red;
  background-color: orange;
  
  &:nth-child(1) {
    width: 100px;
    height: 100px;
  }
  
  &:nth-child(2) {
    width: 140px;
    height: 70px;
  }
  
  &:nth-child(3) {
    width: 70px;
    height: 120px;
  }
}

Position Relative 1

์œ„์™€ ๊ฐ™์ด ๋ธ”๋Ÿญ ์—˜๋ฆฌ๋จผํŠธ div๊ฐ€ ์ฐจ๋ก€๋Œ€๋กœ ์Œ“์—ฌ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ 2๋ฒˆ ์ƒ์ž๋ฅผ relative ๋ฅผ ์ด์šฉํ•ด ์ด๋™์‹œ์ผœ๋ณด์ž.

&:nth-child(2) {
  width: 140px;
  height: 70px;
  position: relative;
  top: 30px;
  left: 120px;
}

Position Relative 2

2๋ฒˆ ์ƒ์ž์˜ ๊ณต๊ฐ„์ด ๋น„์—ˆ์ง€๋งŒ, Flex - Order ์ฒ˜๋Ÿผ ์‹œ๊ฐ์ ์œผ๋กœ๋งŒ ์ด๋™๋œ ๊ฒƒ์ผ ๋ฟ ์ฒ˜๋Ÿผ ์‹ค์ œ ๋ฐฐ์น˜๊ฐ€ ์ด๋™ํ•œ ๊ฒƒ์€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— 3๋ฒˆ ์ƒ์ž์˜ ๋ฐฐ์น˜์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค.

relative๋Š” Position - Relative์™€ ๊ฐ™์ด ์ž์‹ ์˜ ์œ„์น˜๋ฅผ ์ƒ๋Œ€๊ฐ’์œผ๋กœ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋„ ์‚ฌ์šฉํ•˜์ง€๋งŒ ์ด๋Ÿฐ์‹์˜ ๋ฐฐ์น˜๋Š” ์‹œ๊ฐ์ ์œผ๋กœ ๋นˆ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด๋‚ด๊ณ , ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฌด์–ธ๊ฐ€ ๋ˆ„๋ฝ๋œ ๋Š๋‚Œ์„ ์ค„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฑฐ์˜ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. ์ฃผ๋กœ ์ž์‹์˜ absolute์— ์ ์šฉ๋  โ‘  ์œ„์น˜๋ฅผ ๊ธฐ์ค€์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค.

.container {
  width: 300px;
  background-color: royalblue;
  position: relative;
}

.container .item {
  border: 4px dashed red;
  background-color: orange;
  
  &:nth-child(1) {
    width: 100px;
    height: 100px;
  }
  
  &:nth-child(2) {
    width: 140px;
    height: 70px;
    position: absolute;
    bottom: 30px;
    right: 30px;
  }
  
  &:nth-child(3) {
    width: 70px;
    height: 120px;
  }
}

Position Relative 3

2. Stack Order โญ๏ธ

  1. ์—˜๋ฆฌ๋จผํŠธ์— position ์†์„ฑ์˜ ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ ๋” ์œ„์— ์Œ“์ธ๋‹ค (default ๊ฐ’ ์ธ static ์€ ์ œ์™ธ).
  2. 1๋ฒˆ ์กฐ๊ฑด์ด ๋™์ผํ•œ ๊ฒฝ์šฐ, z-index๊ฐ’์ด ๋†’์„ ์ˆ˜๋ก ์œ„์— ์Œ“์ธ๋‹ค.
  3. 2๋ฒˆ๊นŒ์ง€ ์กฐ๊ฑด์ด ๋™์ผํ•œ ๊ฒฝ์šฐ, HTML ์ด ๋‚˜์ค‘์— ์ž‘์„ฑ๋  ์ˆ˜๋ก ์œ„์— ์Œ“์ธ๋‹ค.

3. z-index

์—˜๋ฆฌ๋จผํŠธ์˜ Z์ถ• ๋†’์ด๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • auto, 0: default.
  • ์–‘์ˆ˜: ์ˆซ์ž๊ฐ€ ๋†’์„ ์ˆ˜๋ก ์œ„์— ์Œ“์ž„.
  • ์Œ์ˆ˜: ์Œ์ˆ˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‚˜, ์ผ๋ฐ˜์ ์œผ๋กœ -1 ์™ธ ๋” ์ž‘์€ ์Œ์ˆ˜๊ฐ’์€ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋ณต์žกํ•˜๊ณ  ์ค‘์ฒฉ๋œ z-index ๊ตฌ์กฐ๊ฐ€ ํ•„์š”ํ•˜๋ฉด ์–‘์ˆ˜ ์‚ฌ์šฉ.

z-index๋ฅผ ๊ด€๋ฆฌํ•  ๋•Œ, 999์™€ ๊ฐ™์€ ๊ฐ’์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ์ถ”ํ›„ ๋” ์œ„์— ์Œ“์—ฌ์•ผ ํ•œ๋‹ค๋ฉด ์ด๊ฒƒ๋ณด๋‹ค ๋” ํฐ ๊ฐ’์ด ํ•„์š”ํ•˜๊ฒŒ๋˜๊ณ , ๊ด€๋ฆฌ๊ฐ€ ํž˜๋“ค์–ด์ง„๋‹ค. ๊ฐ€๊ธ‰์  1๋ถ€ํ„ฐ ์ˆœ์ฐจ์ ์œผ๋กœ ์‚ฌ์šฉํ•ด ๋‚˜์•„๊ฐ€๋„๋ก ํ•œ๋‹ค.


6. CSS Flex Layout ๐Ÿ‘ฉโ€

Flex๋Š” container ์— ์ง€์ •ํ•˜๋Š” ์†์„ฑ๊ณผ Item์— ์ง€์ •ํ•˜๋Š” ์†์„ฑ์œผ๋กœ ๋‚˜๋‰œ๋‹ค.

1. flex direction and wrap(container)

  • display
    • flex: ๋ธ”๋Ÿญ ์—˜๋ฆฌ๋จผํŠธ ์†์„ฑ์„ ๊ฐ–๋Š” flex ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์˜ํ•œ๋‹ค.
    • inline-flex: ์ธ๋ผ์ธ ์—˜๋ฆฌ๋จผํŠธ ์†์„ฑ์„ ๊ฐ–๋Š” flex ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์˜ํ•œ๋‹ค.
  • flex-direction: main-axis ์˜ ๋ฐฉํ–ฅ์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ. ๋‹จ์ˆœํžˆ row, column ๋งŒ ์ง€์ •ํ•˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ์ถ•๊ณผ ๋ฐฉํ–ฅ์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ž„์„ ๊ธฐ์–ตํ•ด์•ผํ•œ๋‹ค.
    • row: default, left -> right
    • row-reverse: right -> left
    • column: top -> bottom
    • column-reverse: bottom -> top
  • flex-wrap: ์ปจํ…Œ์ด๋„ˆ์— ์ง€์ •ํ•˜๋Š” ์†์„ฑ์œผ๋กœ, ์•„์ดํ…œ์˜ ์ค„๋ฐ”๊ฟˆ ์—ฌ๋ถ€๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.
    • nowrap: ์ค„๋ฐ”๊ฟˆ ์—†์Œ.
    • wrap: ์—ฌ๋Ÿฌ ์ค„์„ ํ•˜๋‚˜์˜ ์ปจํ…Œ์ด๋„ˆ๋กœ wrapping. ์ค„๋ฐ”๊ฟˆ ์žˆ์Œ.
    • wrap-reverse: wrap ์˜ ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์œผ๋กœ wrapping.

๋งŒ์•ฝ bottom-right ์—์„œ ์‹œ์ž‘ํ•ด์„œ top-left ๋กœ ์™„์ „ ์—ญ์ˆœ์œผ๋กœ ์Œ“๊ณ ์ž ํ•œ๋‹ค๋ฉด, flex-flow: row-reverse wrap-reverse; ๋˜๋Š” flex-flow: column-reverse wrap-reverse;๋ฅผ ์‚ฌ์šฉํ•ด ์™„์ „ํ•œ ์—ญ์ˆœ์„ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

2. justify-content(container)

main-axis ์˜ ์ •๋ ฌ ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • flex-start: ์‹œ์ž‘์  ์ •๋ ฌ.
  • flex-end: ๋์  ์ •๋ ฌ.
  • center: ๊ฐ€์šด๋ฐ ์ •๋ ฌ.
  • space-around: ์–‘ ๋์ด ๋ถ™์ง€ ์•Š๋Š”๋‹ค. ์ด๋ฆ„๊ณผ ๊ฐ™์ด ์•„์ดํ…œ ์ฃผ๋ณ€์œผ๋กœ ๊ณต๊ฐ„์ด ์ƒ๊ธด๋‹ค. ์ด๊ฒƒ์€ ๊ฐ ์•„์ดํ…œ์— ๋™์ผํ•œ padding ์„ ์ค€ ๊ฒƒ๊ณผ ๊ฐ™๋‹ค(padding ์€ collapsing ์ด ์—†์œผ๋ฏ€๋กœ, ์•„์ดํ…œ-์•„์ดํ…œ์˜ ๊ฐ„๊ฒฉ์€ ์•„์ดํ…œ-์‹œ์ž‘์ /๋์  ๊ฐ„๊ฒฉ์˜ 2๋ฐฐ๊ฐ€ ๋œ๋‹ค). Space-Around
  • space-evenly: ์–‘ ๋์ด ๋ถ™์ง€ ์•Š๋Š”๋‹ค. ์ด๋ฆ„๊ณผ ๊ฐ™์ด ๋ชจ๋“  ๊ณต๊ฐ„์ด ๋™์ผํ•œ ํฌ๊ธฐ๋ฅผ ๊ฐ–๋Š”๋‹ค. ์ด๊ฒƒ์€ ๊ฐ ์•„์ดํ…œ์— ๋™์ผํ•œ margin ์„ ์ค€ ๊ฒƒ๊ณผ ๊ฐ™๋‹ค(margin-collapsing ์ด ๋ฐœ์ƒํ•˜๋“ฏ ์•„์ดํ…œ-์•„์ดํ…œ ๊ฐ„๊ฒฉ์ด 2๋ฐฐ๊ฐ€ ์•„๋‹Œ 1๋ฐฐ๋กœ ์ƒ์‡„๋œ๋‹ค). Space-Evenly
  • space-between: ์–‘ ๋์ด ์‹œ์ž‘์ ๊ณผ ๋์ ์— ๋ถ™๋Š”๋‹ค. ์ด๋ฆ„๊ณผ ๊ฐ™์ด ์•„์ดํ…œ ์‚ฌ์ด์— ๋ฐฐ์น˜๋œ๋‹ค. 2๊ฐœ๊นŒ์ง€๋Š” ์–‘ ๋์ ์œผ๋กœ ๋ฐฐ์น˜๋˜๊ณ , 3๊ฐœ์งธ๋ถ€ํ„ฐ ๋‘ ์•„์ดํ…œ ์‚ฌ์ด์— ๋‚ด๋ถ€ ์—ฌ๋ฐฑ์„ ๊ท ๋“ฑํ•˜๊ฒŒ ๊ฐ–๋„๋ก ๋ฐฐ์น˜๋œ๋‹ค. Space-Between

3. align-content, align-items(container)

  • align-content: cross-axis ์˜ ์ •๋ ฌ ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ. stretch ๋ฅผ ์ œ์™ธํ•˜๋ฉด justify-content์™€ ์™„์ „ํžˆ ๋™์ผํ•œ ๋ฐฐ์น˜ ํŠน์„ฑ์„ ๊ฐ€์ง€๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ wrapping ๋˜์–ด 2์ค„ ์ด์ƒ์ผ ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.
    • stretch: default, ์•„์ดํ…œ์˜ ๋†’์ด๊ฐ€ ์ง€์ •๋˜์ง€ ์•Š์•˜์„ ๊ฒฝ์šฐ, ์•„์ดํ…œ์˜ height ๋Š” auto๊ฐ€ ๋˜์–ด ์ปจํ…Œ์ด๋„ˆ ๋†’์ด ๋งŒํผ ๊ณต๊ฐ„์„ ์ฑ„์šด๋‹ค. ๋ฐ˜๋ฉด, ์•„์ดํ…œ ๋†’์ด๊ฐ€ ์ง€์ •๋˜์—ˆ์„ ๊ฒฝ์šฐ ์‚ฌ์‹ค์ƒ flex-start์™€ ๊ฐ™๋‹ค.
    • ๊ทธ ์™ธ flex-start, flex-end, center, space-around, space-evenly, space-between์€ justify-content ์™€ ๊ฐ™๋‹ค.
  • align-items: cross-axis ์˜ ์ •๋ ฌ ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ. align-content: stretch;๋ผ๋Š” ๊ฐ€์ • ํ•˜์— ์ ์šฉ๋˜๋Š” ์†์„ฑ์œผ๋กœ, align-content ๊ฐ€ stretch ๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๊ฐ’์„ ๊ฐ€์ง€๋ฉด align-items ์˜ !important ๋ณด๋‹ค๋„ ๋†’์€ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ€์ ธ align-items ๋Š” ๋ฌด์‹œ๋œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ, 1์ค„์ผ ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.
    • stretch: default, ์•„์ดํ…œ์˜ ๋†’์ด๊ฐ€ ์ง€์ •๋˜์ง€ ์•Š์•˜์„ ๊ฒฝ์šฐ, ์•„์ดํ…œ์„ height ๋Š” auto๊ฐ€ ๋˜์–ด ์ปจํ…Œ์ด๋„ˆ ๋†’์ด ๋งŒํผ ๊ณต๊ฐ„์„ ์ฑ„์šด๋‹ค. ๋ฐ˜๋ฉด, ์•„์ดํ…œ ๋†’์ด๊ฐ€ ์ง€์ •๋˜์—ˆ์„ ๊ฒฝ์šฐ ์‚ฌ์‹ค์ƒ flex-start์™€ ๊ฐ™๋‹ค.
    • flex-start, flex-end, center๋Š” align-content ๊ฐ€ 1์ค„์ผ ๋•Œ ์ ์šฉํ•œ ๊ฒƒ๊ณผ ๋™์ผํ•œ ํšจ๊ณผ๋ฅผ ๊ฐ–๋Š”๋‹ค.
    • align-content ์™€ ๋‹ฌ๋ฆฌ space-around, space-evenly, space-between์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค.


align-content, align-items ์–ด๋–ค๊ฑธ ์‚ฌ์šฉํ• ๊นŒ?

  • ์ผ๋ฐ˜์ ์œผ๋กœ 1์ค„์ด๋ฉด align-items, 2์ค„ ์ด์ƒ์ด๋ฉด align-content ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ•˜์ง€๋งŒ 1์ค„์ด๋ผ๊ณ  align-content ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. align-items ๋Š” wrap, no-wrap ๋ชจ๋‘์— ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ณ , align-content ๋Š” wrap ์ผ ๊ฒฝ์šฐ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ•œ ๊ฒƒ์ด ์ค‘์š”ํ•œ ์ฐจ์ด์ ์ด๋‹ค. wrap ์ด๋ฉด์„œ ์‹ค์ œ๋กœ ๊ทธ๋ ค์ง€๋Š” ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ 2์ค„์ด ๋˜์—ˆ์„ ๋•Œ์˜ ์ •๋ ฌ ๋ชจ์–‘์ด ๋‹ค๋ฅด๋ฏ€๋กœ ์šฉ๋„์— ๋งž๊ฒŒ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.
  • 1์ค„์ผ ๋•Œ align-items ์™€ align-content ์˜ stretch, flex-start, flex-end, center๋Š” ๋™์ผํ•œ ํšจ๊ณผ๋ฅผ ๊ฐ–๋Š”๋‹ค.
  • 2์ค„์ผ ๋•Œ align-items ์™€ align-content ์˜ stretch๋Š” ๋™์ผํ•˜์ง€๋งŒ flex-start, flex-end, center๋Š” ๋‹ค๋ฅธ ํšจ๊ณผ๋ฅผ ๊ฐ–๋Š”๋‹ค (2์ค„์ผ ๋•Œ align-items ์ ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•จ์ด ์•„๋‹˜์— ์œ ์˜).
  • align-items ๋Š” 2์ค„ ์ด์ƒ์ผ ๋•Œ๋งŒ ์ ์šฉ ๊ฐ€๋Šฅํ•œ space-around, space-evenly, space-between์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ด ํšจ๊ณผ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด align-content ๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.
  • align-content ๊ฐ€ stretch ๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๊ฐ’์„ ๊ฐ€์ง€๋ฉด, align-items ์˜ !importnat ๋ณด๋‹ค๋„ ๋†’์€ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ–๋Š”๋‹ค.

align-items flex-start

- align-items: flex-start -

align-content flex-start

- align-content: flex-start -


align-items center

- align-items: center -

align-content center

- align-content: center -

๋งŽ์€ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ CSS ๋ฅผ ์ ์šฉํ•ด

justify-content, align-content์™€ ๊ฐ™์ด content ๋ฅผ ์ •๋ ฌํ•œ๋‹ค๋Š” ๊ฒƒ์€, main-axis ๊ฐ€ ๋˜์—ˆ๋“  cross-axis ๊ฐ€ ๋˜์—ˆ๋“  ๊ฐ ์ถ•์˜ ์•„์ดํ…œ๋“ค์ด ์–ด๋–ค ๋ถ„ํฌ๋กœ ๋ฐฐ์น˜๋˜๋Š”์ง€๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋ฐ˜๋ฉด, align-items๋Š” align-content์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ cross-axis ์— ๋Œ€ํ•œ ์ •๋ ฌ์„ ์ง€์ •ํ•˜์ง€๋งŒ, wrap ์ƒํƒœ์ด๋“ , nowrap ์ƒํƒœ์ด๋“  ์•„์ดํ…œ๋“ค์˜ ๋ฌถ์Œ์ด ์ปจํ…Œ์ด๋„ˆ ๋ผ์ธ์—์„œ ์–ด๋Š ์œ„์น˜์— ๋ถ„ํฌํ• ์ง€๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ฆ‰, cross-axis ์ถ•์˜ ์•„์ดํ…œ์˜ ๋ถ„ํฌ๊ฐ€ ์•„๋‹Œ main-axis ์˜ ์ถ• ์ž์ฒด๋ฅผ cross-axis ๋ฐฉํ–ฅ์˜ ์–ด๋””์— ์œ„์น˜ํ• ๊ฑด์ง€ ํ‰ํ–‰์ด๋™ ์‹œํ‚ค๋Š” ๊ฐœ๋…์— ๊ทผ์ ‘ํ•œ๋‹ค.

4. align-self(item)

์•„์ดํ…œ์„ ๊ฐœ๋ณ„์ ์œผ๋กœ cross-axis ์˜ ์ •๋ ฌ ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ. ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์•„๋‹Œ ์•„์ดํ…œ์— ์ง€์ •ํ•˜๋Š” ์†์„ฑ์ด๋‹ค.

.container {
  width: 100vw;
  height: 100vh;
  background-color: royalblue;
  display: flex;
  flex-wrap: wrap;

  .item {
    width: 100px;
    height: 100px;
    border: 4px dashed red;
    background-color: orange;

    &:nth-child(1) {
      align-self: center;
    }

    &:nth-child(even) {
      align-self: flex-end;
    }
  }
}

align-self 1

.container {
  width: 100vw;
  height: 100vh;
  background-color: royalblue;
  display: flex;
  flex-wrap: wrap;

  .item {
    width: 100px;
    height: 100px;
    border: 4px dashed red;
    background-color: orange;

    &:nth-child(even) {
      align-self: flex-end;
    }
  }
}

align-self 2

5. order(item)

์•„์ดํ…œ์˜ ์ •๋ ฌ ์ˆœ์„œ๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • 0: default, ์ˆœ์„œ ์—†์Œ.
  • ์ˆซ์ž: ์ˆซ์ž๊ฐ€ ์ž‘์„์ˆ˜๋ก ์‹œ์ž‘์ ์—, ํด ์ˆ˜๋ก ๋์ ์— ์œ„์น˜ํ•œ๋‹ค(์–‘์ˆ˜, ์Œ์ˆ˜ ๋ชจ๋‘ ์‚ฌ์šฉ ๊ฐ€๋Šฅ).

HTML ์˜ ์ˆ˜์ • ์—†์ด ์•„์ดํ…œ ์ •๋ ฌ ์ˆœ์„œ๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

.container {
  width: 100vw;
  height: 100vh;
  background-color: royalblue;
  display: flex;
  flex-wrap: wrap;

  .item {
    width: 100px;
    height: 100px;
    border: 4px dashed red;
    background-color: orange;

    &:nth-child(1) {
      order: 2;
    }
    
    &:nth-child(3) {
      order: 1;
    }
    
    &:nth-child(5) {
      order: -1;
    }
  }
}

flex order

6. flex-grow & flex-basis(item)

์•„์ดํ…œ์˜ ๋„ˆ๋น„๊ฐ€ ์ฆ๊ฐ€๋˜๋Š” ๋น„์œจ์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

flex ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ปจํ…Œ์ด๋„ˆ์˜ ๋„ˆ๋น„๋ฅผ ์•„์ดํ…œ์˜ ๋„ˆ๋น„๊ฐ€ ์ •ํ™•ํžˆ ์ •์ˆ˜๋ฐฐ๋กœ ์ผ์น˜ํ•ด ๋นˆ ๊ณต๊ฐ„ ์—†์ด ๊ฐ€๋“ ์ฑ„์šฐ์ง€ ์•Š๋Š” ํ•œ ํ•ญ์ƒ ๋นˆ ๊ณต๊ฐ„์ด ๋‚จ๊ฒŒ ๋œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ์˜ ํฌ๊ธฐ๊ฐ€ ๊ณ ์ •๋˜์–ด ์žˆ๋‹ค๋ฉด ์•„์ดํ…œ์ด ์ง€์ •๋œ ์ž์‹ ์˜ ํฌ๊ธฐ๋ณด๋‹ค ๋” ์ปค์ง€๋„๋ก ๋Š˜์–ด๋‚˜์•ผํ•œ๋‹ค.

  • 0: default, ์ฆ๊ฐ€ ๋น„์œจ ์—†์Œ.
  • ์ˆซ์ž: ์ฆ๊ฐ€ ๋น„์œจ ์ง€์ •.
  • ์•„์ดํ…œ ์ „์ฒด๋ฅผ ๊ท ์ผํ•˜๊ฒŒ ๋Š˜๋ฆฌ๊ธฐ
.container {
  width: 100vw;
  height: 100vh;
  background-color: royalblue;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;

  .item {
    width: 100px;
    height: 100px;
    border: 4px dashed red;
    background-color: orange;
    flex-grow: 1;
  }
}

flex-grow 1

์•„์ดํ…œ ์ „์ฒด์— flex-grow ๋ฅผ 0์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๊ฐ’์„ ์ฃผ๋ฉด ๊ฐ™์€ ๋น„์œจ๋กœ ๋Š˜์–ด๋‚œ๋‹ค.

  • ์„œ๋กœ ๋‹ค๋ฅธ ๋น„์œจ๋กœ ๋Š˜๋ฆฌ๊ธฐ(๋ฐ˜๋“œ์‹œ flex-basis: 0; ์†์„ฑ์„ ์ค˜์•ผ ํ•œ๋‹ค)
.container {
  width: 100vw;
  height: 100vh;
  background-color: royalblue;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;

  .item {
    width: 100px;
    height: 100px;
    border: 4px dashed red;
    background-color: orange;
    flex-grow: 1;
    flex-basis: 0;

    &:nth-child(3) {
      flex-grow: 2;
    }
  }
}

flex-grow 2

๋ชจ๋“  ์•„์ดํ…œ์— ๋™์ผํ•œ 1์˜ ๋น„์œจ์„ ์ค€ ๋‹ค์Œ 3๋ฒˆ์งธ ์•„์ดํ…œ๋งŒ 2๊ฐ€ ๋ฎ์–ด ์ผ๊ธฐ ๋•Œ๋ฌธ์— 1:1:2๋กœ ๋Š˜์–ด๋‚œ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ flex-grow ์™€ flex-shrink ์ด ๋Š˜์–ด๋‚˜๊ณ  ์ค„์–ด๋“œ๋Š” ๋น„์œจ์€ ์•„์ดํ…œ์˜ ํฌ๊ธฐ ๋น„์œจ์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ์•„์ดํ…œ์˜ content ๋ฅผ ์ œ์™ธํ•œ ์—ฌ๋ฐฑ์ด ๋Š˜์–ด๋‚˜๊ฑฐ๋‚˜ ์ค„์–ด๋“œ๋Š” ๋น„์œจ์„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋”ฐ๋ผ์„œ ๋‚ด๋ถ€ content ์— ์˜ํ–ฅ์„ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์‹œ๊ฐ์ ์œผ๋กœ ์•„์ดํ…œ์˜ ํฌ๊ธฐ ์ž์ฒด์˜ ๋น„์œจ๋กœ ๊ณ„์‚ฐ๋˜๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด content ๋ฅผ 0์œผ๋กœ ๊ณ ์ •์‹œํ‚ค๋Š” ์†์„ฑ๊ฐ’์ด flex-basis: 0;์ด๋‹ค.


  • flex-basis: 0 ์„ ์„ค์ •ํ•˜์ง€ ์•Š์•˜์„ ๋•Œ content ๋ฅผ ์ œ์™ธํ•œ ์—ฌ๋ฐฑ์˜ ๋น„์œจ๋Œ€๋กœ ๋Š˜์–ด๋‚˜๋Š” ๋ชจ์Šต
section article:nth-of-type(1) {
  flex-grow: 1;
}
section article:nth-of-type(2) {
  flex-grow: 2;
}
section article:nth-of-type(3) {
  flex-grow: 3;
}

Flew Grow 3

์•„์ดํ…œ์ด ์•„๋‹Œ content ๋ฅผ ์ œ์™ธํ•œ ์—ฌ๋ฐฑ์ด 1:2:3 ๋น„์œจ๋กœ ๋Š˜์–ด๋‚œ๋‹ค.

7. flex-shrink(item)

์•„์ดํ…œ์˜ ๋„ˆ๋น„๊ฐ€ ๊ฐ์†Œ๋˜๋Š” ๋น„์œจ์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

flex-grow ๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ฑ„์šฐ๊ธฐ ์œ„ํ•ด ์•„์ดํ…œ์ด ์ง€์ •๋œ ์ž์‹ ์˜ ํฌ๊ธฐ๋ณด๋‹ค ๋” ์ปค์ง€๋„๋ก ๋Š˜์–ด๋‚ฌ๋‹ค. ์ด๋ฒˆ์—” ๋ฐ˜๋Œ€๋กœ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์•„์ดํ…œ์ด ํฌ๊ธฐ๋ฅผ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๊ณต๊ฐ„๋ณด๋‹ค ์ž‘์„ ๋•Œ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— ์กด์žฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ ค๋ฉด โ‘  wrapping ์‹œ์ผœ ์ค„์ด ๋‚˜๋‰˜๋”๋ผ๋„ ํ•˜๋‚˜์˜ ์ปจํ…Œ์ด๋„ˆ๋กœ ๋ฌถ์ด๋„๋ก ์—ฌ๋Ÿฌ ์ค„์„ ๋งŒ๋“ค๊ฑฐ๋‚˜, โ‘ก ์•„์ดํ…œ์ด ์ค„์–ด๋“  ์ปจํ…Œ์ด๋„ˆ์— ๋งž๊ฒŒ ํ•จ๊ป˜ ์ค„์–ด์•ผํ•œ๋‹ค.

  • 1: default, ๋„ˆ๋น„์— ๋”ฐ๋ผ ๊ฐ์†Œ ๋น„์œจ ์ ์šฉ.
  • ์ˆซ์ž: ๊ฐ์†Œ ๋น„์œจ ์ง€์ •.
  • 0: ๊ฐ์†Œ ๋„ˆ๋น„ ์—†์Œ.
  • flex-shrink ๊ฐ€ 0 ์ด๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์•„์ดํ…œ์ด ์ฐจ์ง€ํ•˜๋Š” ๊ณต๊ฐ„๋ณด๋‹ค ์ค„์–ด๋“ค๋ฉด ์•„์ดํ…œ์ด ์ปจํ…Œ์ด๋„ˆ ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ€๊ฒŒ ๋œ๋‹ค.

flex-shrink

์ผ๋ฐ˜์ ์ด์ง€๋Š” ์•Š์ง€๋งŒ ๋•Œ๋กœ๋Š” flex-wrap ๋Œ€์‹  ์•„์ดํ…œ์ด ํฌ๊ธฐ๋ฅผ ์œ ์ง€ํ•˜๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด flex-shrink ์— 0์„ ์ฃผ๊ธฐ๋„ ํ•œ๋‹ค.

flex-grow ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์•„์ดํ…œ์˜ ํฌ๊ธฐ ๋น„์œจ์ด ์•„๋‹Œ ์•„์ดํ…œ์˜ content ๋ฅผ ์ œ์™ธํ•œ ์—ฌ๋ฐฑ์ด ์ค„์–ด๋“œ๋Š” ๋น„์œจ์„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋‹จ, flex-grow ์™€ ๋‹ค๋ฅด๊ฒŒ flex-basis ๋ฅผ 0์œผ๋กœ ์ฃผ๊ฒŒ ๋˜๋ฉด ์ตœ์†Œํ•œ์˜ content ์˜์—ญ์ด ๋ณด์žฅ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์‹ค์ œ content ๊ณต๊ฐ„์„ ์ œ์™ธํ•œ ๋ชจ๋“  ์—ฌ๋ฐฑ์ด ์™„์ „ํžˆ ์ค„์–ด๋“ค๊ฒŒ ๋œ๋‹ค. ์ฆ‰, ํ•ญ์ƒ ์•„์ดํ…œ ๋„ˆ๋น„๊ฐ’์ด auto์ธ ๊ฒƒ๊ณผ ๊ฐ™์•„์ ธ๋ฒ„๋ฆฐ๋‹ค. ๋”ฐ๋ผ์„œ flex-shrink ๋Š” flex-grow ์™€ ๋‹ฌ๋ฆฌ ์•„์ดํ…œ์˜ ๋น„์œจ์„ ์‹œ๊ฐ์ ์œผ๋กœ ๋งž์ถ”๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค.


  • ์ผ๋ฐ˜์ ์œผ๋กœ flex-shrink ๊ฐ€ ์ค„์–ด๋“œ๋Š” ๋ฐฉ์‹
section article:nth-of-type(1) {
  flex: 3;
}
section article:nth-of-type(2) {
  flex: 2;
}
section article:nth-of-type(3) {
  flex: 1;
}

Flex Shrink 3

์•„์ดํ…œ์ด ์•„๋‹Œ content ๋ฅผ ์ œ์™ธํ•œ ์—ฌ๋ฐฑ์ด 1/3 : 1/2 : 1์˜ ๋น„์œจ๋กœ ์ค„์–ด๋“ ๋‹ค.

8. flex-basis(item)

์•„์ดํ…œ ๊ณต๊ฐ„ ๋ฐฐ๋ถ„ ์ „ ๊ธฐ๋ณธ ๋„ˆ๋น„

  • auto: ์—˜๋ฆฌ๋จผํŠธ์˜ content ๋„ˆ๋น„.
  • ๋‹จ์œ„๊ฐ’: px, em, rem ๋“ฑ ๋‹จ์œ„๋ฅผ ์ง€์ •ํ•œ๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ content ์˜ ํฌ๊ธฐ๋ฅผ CSS ๋กœ ์ •์˜ํ•  ์ผ์ด ๊ฑฐ์˜ ์—†๋‹ค. ์ •์˜ํ•œ๋‹ค ํ•˜๋”๋ผ๋„ ์‹ค์ œ HTML ์— ์กด์žฌํ•˜๋Š” content ์˜ ํฌ๊ธฐ๊ฐ€ ์šฐ์„  ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด๊ฒƒ์€ flex-grow ์—์„œ ๋ณธ ๊ฒƒ์ฒ˜๋Ÿผ ์ฃผ๋กœ flex-grow ์˜ ๋Š˜์–ด๋‚˜๋Š” ๋น„์œจ์ด ์‹œ๊ฐ์ ์œผ๋กœ ์•„์ดํ…œ ๋น„์œจ๊ณผ ์ผ์น˜ํ•˜๋„๋ก content ํฌ๊ธฐ๋ฅผ 0์œผ๋กœ ๊ณ ์ • ํ›„ ๊ณ„์‚ฐํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค.


7. Animation - Transition ๐Ÿ‘ฉโ€

์—˜๋ฆฌ๋จผํŠธ์˜ ์ „ํ™˜(์‹œ์ž‘๊ณผ ๋) ํšจ๊ณผ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋‹จ์ถ• ์†์„ฑ.

transition: property duration timing-function delay ์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉฐ, ๋‹จ์ถ• ์†์„ฑ์œผ๋กœ ์ •์˜์‹œ ์ง€์†์‹œ๊ฐ„์€ ๋ฐ˜๋“œ์‹œ ๋ฐ˜๋“œ์‹œ ์ž‘์„ฑํ•ด์•ผํ•œ๋‹ค.

1. transition-property

์ „ํ™˜ ํšจ๊ณผ๋ฅผ ์‚ฌ์šฉํ•  ์†์„ฑ ์ด๋ฆ„์„ ์ง€์ •.

  • all: default, ๋ชจ๋“  ์†์„ฑ์— ์ ์šฉ.
  • ์†์„ฑ๋ช…: ์ „ํ™˜ ํšจ๊ณผ๋ฅผ ์‚ฌ์šฉํ•  ์†์„ฑ ์ด๋ฆ„ ๋ช…์‹œ.

2. transition-duration

์ „ํ™˜ ํšจ๊ณผ์˜ ์ง€์†์‹œ๊ฐ„์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • 0: default, ์ „ํ™˜ ํšจ๊ณผ ์—†์Œ.
  • ์‹œ๊ฐ„: ์ง€์†์‹œ๊ฐ„์„ 1s์™€ ๊ฐ™์ด ์ดˆ ๋‹จ์œ„๋กœ ์ง€์ •.
div {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition: 1s;
}

div:active {
  width: 300px;
  background-color: royalblue;
}

width, background-color ๋ชจ๋‘์— ์ „ํ™˜ ํšจ๊ณผ duration 1s๊ฐ€ ์ ์šฉ๋˜์—ˆ๋‹ค.


div {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition: width 1s;
}

div:active {
  width: 300px;
  background-color: royalblue;
}

width ์—๋งŒ ์ „ํ™˜ ํšจ๊ณผ duration 1s๊ฐ€ ์ ์šฉ๋˜์—ˆ๋‹ค.


div {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition:
      background-color 1s,
      width 2s;
}

div:active {
  width: 300px;
  background-color: royalblue;
}

background-color ์—๋Š” ์ „ํ™˜ ํšจ๊ณผ duration 1s๊ฐ€, width ์—๋Š” ์ „ํ™˜ ํšจ๊ณผ duration 2s๊ฐ€ ์ ์šฉ๋˜์—ˆ๋‹ค.

3. transition-timing-function

์ „ํ™˜ ํšจ๊ณผ์˜ ํƒ€์ด๋ฐ(Easing) ํ•จ์ˆ˜๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • ease: default, ๋Š๋ฆฌ๊ฒŒ - ๋น ๋ฅด๊ฒŒ - ๋Š๋ฆฌ๊ฒŒ = cubic-bezier(0.25, 0.1, 0.25, 1)
  • linear: ์ผ์ •ํ•˜๊ฒŒ = cubic-bezier(0, 0, 1, 1)
  • ease-in: ๋Š๋ฆฌ๊ฒŒ - ๋น ๋ฅด๊ฒŒ = cubic-bezier(0.42, 0.1, 1)
  • ease-out: ๋น ๋ฅด๊ฒŒ - ๋Š๋ฆฌ๊ฒŒ = cubic-bezier(0, 0, 0.58, 1)
  • ease-in-out: ๋Š๋ฆฌ๊ฒŒ - ๋น ๋ฅด๊ฒŒ - ๋Š๋ฆฌ๊ฒŒ = cubic-bezier(0.42, 0, 0.58, 1)
  • steps(n): n ๋ฒˆ ๋ถ„ํ• ๋œ ์• ๋‹ˆ๋ฉ”์ด์…˜.
div {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition: 1s steps(10);
}

div:active {
  width: 300px;
  background-color: royalblue;
}

์ „ํ™˜ ํšจ๊ณผ easing ํ•จ์ˆ˜ steps(10)๊ฐ€ ์ ์šฉ๋„์–ด 10๋‹จ๊ณ„๋กœ ๋‚˜๋‰˜์–ด ์ „ํ™˜๋œ๋‹ค.

cubic-bezier(n, n, n, n)์„ ์ง์ ‘ ์ •์˜ํ•  ์ˆ˜๋„ ์žˆ๋Š”๋ฐ, ์ด๋•Œ n ์— ๋“ค์–ด๊ฐˆ ์ˆซ์ž๊ฐ’์€ ์ง์ ‘ ๊ณ„์‚ฐํ•  ํ•„์š”๋Š” ์—†๊ณ  easings.net ์— ๋ฐฉ๋ฌธ์— ์‚ฌ์ „์— ์ •์˜๋œ ๋‹ค์–‘ํ•œ ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ ธ๋‹ค ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, cubic-bezier.com ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•ด ๊ทธ๋ž˜ํ”„๋ฅผ ์ด์šฉํ•ด ํ•จ์ˆ˜๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

Easing Functions ์— ๋Œ€ํ•ด์„œ๋Š” GSAP - Easing ์™€ MDN - easing-function ์—์„œ ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

4. transition-delay

์ „ํ™˜ ํšจ๊ณผ๊ฐ€ ๋ช‡ ์ดˆ ๋’ค์— ์‹œ์ž‘ํ• ์ง€ ๋Œ€๊ธฐ์‹œ๊ฐ„์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • 0: default, ๋Œ€๊ธฐ ์‹œ๊ฐ„ ์—†์Œ.
  • ์‹œ๊ฐ„: ๋Œ€๊ธฐ์‹œ๊ฐ„์„ 1s์™€ ๊ฐ™์ด ์ดˆ ๋‹จ์œ„๋กœ ์ง€์ •.
div {
  width: 100px;
  height: 100px;
  background-color: orange;
  transition: 1s;
}

div:hover {
  width: 300px;
  background-color: royalblue;
  transition: 1s .5s;
}

hover ๊ฐ€ ์ ์šฉ๋  ๋•Œ๋Š” delay 0.5s์— duration 1s๊ฐ€ ์ ์šฉ๋˜๊ณ , ํ•ด์ œ๋  ๋•Œ๋Š” ๋”œ๋ ˆ์ด ์—†์ด duration 1s๋งŒ ์ ์šฉ๋˜์–ด ์ „ํ™˜๋œ๋‹ค.


8. Animation - Transform ๐Ÿ‘ฉโ€

1. Transform 2D

2D ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ์œผ๋กœ ์ฃผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • translate(x, y): ์ด๋™(X์ถ•, Y์ถ•)
  • translateX(x): ์ด๋™(X์ถ•)
  • translateY(y): ์ด๋™(Y์ถ•)
  • scale(x, y): ํฌ๊ธฐ(X์ถ•, Y์ถ•)
  • rotate(degree): ํšŒ์ „(๊ฐ๋„), ํšŒ์ „์ถ•์€ ์ • ์ค‘์•™์ด๋ฉฐ, transform-origin์„ ์‚ฌ์šฉํ•ด ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • skewX(x): ๊ธฐ์šธ์ž„(X์ถ•)
  • skewY(y)): ๊ธฐ์šธ์ž„(Y์ถ•)

์œ„ ํ•จ์ˆ˜๋“ค์€ ๋ชจ๋‘ matrix(n, n, n, n, n, n)์ด๋ผ๋Š” ํ•จ์ˆ˜๋กœ ๋ณ€ํ™˜๋˜์–ด ์‹คํ–‰๋œ๋‹ค. ์ง์ ‘ matrix ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์–ด๋ ต๋‹ค๋ณด๋‹ˆ ๋‚˜์˜จ ํ•จ์ˆ˜๋“ค์ด๋‹ค.

2. Transform 3D

3D ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ์œผ๋กœ ์ฃผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • perspective(n): ์›๊ทผ๋ฒ•(๊ฑฐ๋ฆฌ)
  • rotateX(x): ํšŒ์ „(X์ถ•)
  • rotateY(y): ํšŒ์ „(Y์ถ•)

๋‹จ์ถ• ์†์„ฑ์œผ๋กœ ์ •์˜์‹œ ๋ฐ˜๋“œ์‹œ transform: perspective(500px) rotateX(45deg)์™€ ๊ฐ™์ด perspective ํ•จ์ˆ˜๊ฐ€ ์ฒซ ๋ฒˆ์งธ๋กœ ์™€์•ผ ํ•œ๋‹ค.

2D ์• ๋‹ˆ๋ฉ”์ด์…˜์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋˜ ํ•จ์ˆ˜๋“ค์˜ Z์ถ• ๋ฒ„์ „ translateZ(z), translate3d(x, y, z), scaleZ(z), scale3d(x, y, z), rotateZ(z), rotate3d(x, y, z, a)๊ฐ€ ์กด์žฌํ•œ๋‹ค. ํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ Z์ถ•์„ ์ปจํŠธ๋กค์„ ์ž˜ ์‚ฌ์šฉํ•˜์ง„ ์•Š๋Š”๋‹ค. perspective(n) ์œผ๋กœ ์›๊ทผ๋ฒ•์„ ์ฃผ๋ฉฐ X์ถ•๊ณผ Y์ถ•์„ ํšŒ์ „์‹œํ‚ค๋Š” ์ •๋„๋กœ ์‚ฌ์šฉ๋œ๋‹ค.

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์œ„ ํ•จ์ˆ˜๋“ค์€ ๋ชจ๋‘ matrix3d ํ•จ์ˆ˜๋กœ ๋ณ€ํ™˜๋˜์–ด ์‹คํ–‰๋˜๋Š”๋ฐ, 2D์—์„œ๋Š” 6๊ฐœ์˜€๋˜ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ 3D์—์„œ๋Š” 16๊ฐœ๋กœ ๋Š˜์–ด๋‚œ๋‹ค. ๋”ฐ๋ผ์„œ ์ง์ ‘ matrix ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ์‚ฌ์šฉํ•  ์ผ์€ ์—†๋‹ค๊ณ  ๋ด๋„ ๋œ๋‹ค.

3. Perspective Attributes and Functions

perspective ๋Š” ์†์„ฑ๊ณผ ํ•จ์ˆ˜ ๋‘ ๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•œ๋‹ค. ๋‘˜์€ ๋‹จ์ˆœํžˆ ๋‹จ์ถ• ์†์„ฑ์˜ ๊ด€๊ณ„๊ฐ€ ์•„๋‹ˆ๋ผ ๊ด€์ธก ์ง€์ ์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์‹ค์ œ ๊ฒฐ๊ณผ๋ฌผ ์ž์ฒด๊ฐ€ ๋‹ค๋ฅด๋‹ค. ์†์„ฑ์œผ๋กœ ์‚ฌ์šฉ์‹œ transform ์„ ์ ์šฉํ•˜๋ ค๋Š” ๋Œ€์ƒ์˜ ๋ถ€๋ชจ์— ์†์„ฑ๊ฐ’์„ ์ฃผ์–ด์•ผํ•˜๊ณ , ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉ์‹œ transform ์„ ์ ์šฉํ•˜๋ ค๋Š” ๋Œ€์ƒ์—๊ฒŒ ์ฃผ์–ด์•ผํ•œ๋‹ค.

Type Syntax Apply Target Change Observing Point
Perspective Attributes perspective: 600px Parent perspective-origin
Perspective Functions transform: perspective(600px) Self transform-origin
  • Perspective Attributes
<section>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</section>
section {
  width: 400px;
  height: 100px;
  border: 1px solid #000;
  background-color: #90acfa;
  perspective: 200px;
  display: flex;

  div {
    box-sizing: border-box;
    width: 100px;
    height: 100px;

    &:nth-of-type(1) {
      background-color: #ffa500cc;
      transform: rotateY(45deg);
    }

    &:not(:nth-of-type(1)) {
      border: 1px dashed red;
    }
  }
}

Perspective Attributes

๋ถ€๋ชจ(ํŒŒ๋ž€์ƒ‰ ์ปจํ…Œ์ด๋„ˆ)์˜ ์ค‘์‹ฌ์ด origin(๊ด€์ธก ์ง€์ ) ์ด๊ณ , ์ด ์ง€์ ์—์„œ 200px ๋–จ์–ด์ง„ ์ง€์ ์—์„œ ๊ด€์ฐฐํ•œ๋‹ค.

  • Perspective Functions
section {
  width: 400px;
  height: 100px;
  border: 1px solid #000;
  background-color: #90acfa;
  display: flex;

  div {
    box-sizing: border-box;
    width: 100px;
    height: 100px;

    &:nth-of-type(1) {
      background-color: #ffa500cc;
      transform: perspective(200px) rotateY(45deg);
    }

    &:not(:nth-of-type(1)) {
      border: 1px dashed red;
    }
  }
}

Perspective Functions

์—˜๋ฆฌ๋จผํŠธ(๋…ธ๋ž€์ƒ‰ ๋ฉด)์˜ ์ค‘์‹ฌ์ด origin(๊ด€์ธก ์ง€์ ) ์ด๊ณ , ์ด ์ง€์ ์—์„œ 200px ๋–จ์–ด์ง„ ์ง€์ ์—์„œ ๊ด€์ฐฐํ•œ๋‹ค.

4. backface-visibility

3D ๋ณ€ํ™˜์œผ๋กœ ํšŒ์ „๋œ ์—˜๋ฆฌ๋จผํŠธ์˜ ๋’ท๋ฉด ์ˆจ๊น€ ์—ฌ๋ถ€๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

  • visible: default, ๋’ท๋ฉด ๋ณด์ž„.
  • hidden: ๋’ท๋ฉด ์ˆจ๊น€(0~360๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ณด๋ฉด, 0...<90: ๋ณด์ž„, 90...270: ์ˆจ๊น€, 271...360: ๋ณด์ž„์˜ ํŒจํ„ด์ด ์—ฐ์†๋œ๋‹ค).




Reference

  1. ๋ฐ•์˜์›…, โ€œํ”„๋ก ํŠธ์—”๋“œ ์›น ๊ฐœ๋ฐœ์˜ ๋ชจ๋“  ๊ฒƒ ์ดˆ๊ฒฉ์ฐจ ํŒจํ‚ค์ง€ Online.โ€ fastcampus.co.kr. last modified unknown, Fast Campus.