λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

Web/Html&Css

λ°˜μ‘ν˜• λ ˆμ΄μ•„μ›ƒ

πŸ“’ CSS λ‹¨μœ„ μ•Œμ•„λ³΄κΈ°

βœ” vw

ν˜„μž¬ λΈŒλΌμš°μ € 폭에 λΉ„λ‘€ν•΄μ„œ μ„€μ •ν•  수 μžˆλŠ” λ‹¨μœ„

.test {
  width: 100vw;
  height: 100vw;
  background-color: grey;
}

βœ” vh

ν˜„μž¬ λΈŒλΌμš°μ € 높이에 λΉ„λ‘€ν•΄μ„œ μ„€μ •ν•  수 μžˆλŠ” λ‹¨μœ„

.test {
  width: 100vw;
  height: 50vh;
  background-color: grey;
}

βœ” rem

html νƒœκ·Έ(16px) 폰트 μ‚¬μ΄μ¦ˆμ— λΉ„λ‘€ν•΄μ„œ μ„€μ •ν•  수 μžˆλŠ” λ‹¨μœ„

.test {
  width: 100rem; // 1600px
  height: 50vh;
  background-color: grey;
}

βœ” em

λ‚΄ 폰트 μ‚¬μ΄μ¦ˆμ— λΉ„λ‘€ν•΄μ„œ μ„€μ •ν•  수 μžˆλŠ” λ‹¨μœ„

.test {
  font-size: 15px;
  width: 100rem; // 1500px
  height: 50vh;
  background-color: grey;
}

πŸ“’ λ°˜μ‘ν˜• λ ˆμ΄μ•„μ›ƒ

βœ” head νƒœκ·Έμ— λ‹€μŒ μ½”λ“œλ₯Ό κΈ°μž…ν•œλ‹€.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

β—Ό width=device-width -> μž₯치의 ν™”λ©΄ λ„ˆλΉ„λ₯Ό λ”°λ₯΄λ„둝 νŽ˜μ΄μ§€ λ„ˆλΉ„λ₯Ό μ„€μ •ν•œλ‹€.

β—Ό initial-scale=1.0 -> λΈŒλΌμš°μ €μ—μ„œ νŽ˜μ΄μ§€λ₯Ό μ²˜μŒλ‘œλ“œ ν•  λ•Œ 초기 ν™•λŒ€ / μΆ•μ†Œ μˆ˜μ€€μ„ μ„€μ •ν•œλ‹€.

βœ” CSS νŒŒμΌμ— 브레이크 포인트λ₯Ό μž‘μ„±ν•œλ‹€.

 

@media screen and (max-width: 1200px) {
  .main-title {
    font-size: 30px;
  }
}

β—Ό 1200px μ΄ν•˜μ—μ„œλŠ” .main-title은 font-size 30pxλ₯Ό κ°–λŠ”λ‹€.

β—Ό μ—¬λŸ¬ 개 μ‚¬μš©ν•΄λ„ 상관 μ—†λ‹€.

β—Ό νƒœλΈ”λ¦Ώμ€ 1200px, 992px, λͺ¨λ°”일은 768px, 576pxλ₯Ό 많이 μ‚¬μš©ν•œλ‹€.

 

πŸ“’ 예제

βœ”  PCμ—μ„œλŠ” 1ν–‰ 4μ—΄, νƒœλΈ”λ¦Ώμ—μ„œλŠ” 2ν–‰ 2μ—΄, λͺ¨λ°”μΌμ—μ„œλŠ” 4ν–‰ 1μ—΄λ‘œ λ§Œλ“€κΈ°

.main-container {
  display: flex;
  width: 80%;
  margin: auto;
  margin-top: 50px;
  margin-bottom: 50px;
  flex-wrap: wrap;
}

.main-container div {
  width: 25%;
  text-align: center;
}

@media screen and (max-width: 1200px) {
  .main-container div {
    font-size: 20px;
    width: 50%;
  }
}

@media screen and (max-width: 768px) {
  .main-container div {
    font-size: 30px;
    width: 100%;
  }
}

β—Ό 1200px 초과 -> PC

β—Ό 1200px μ΄ν•˜ ~ 768px 초과 -> νƒœλΈ”λ¦Ώ

β—Ό 768px 미만 -> λͺ¨λ°”일 

 

λ‹€μŒκ³Ό 같이 잘 적용된 것을 확인할 수 μžˆλ‹€.

 

'Web > Html&Css' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

SASS μ‚¬μš©λ²•  (0) 2023.04.21
Html&CSS μœ μš©ν•œ 방법듀  (0) 2023.04.21
Html&CSS μ‚¬μš©ν•˜κΈ°  (0) 2023.03.31