🍎 듀어가기에 μ•žμ„œ

이 글은 λͺ¨λ˜ 웹을 μœ„ν•œ HTML5+CSS3 바이블을 κ³΅λΆ€ν•˜λ©° κΈ°μ–΅ν•΄λ‘˜ λ‚΄μš©λ“€μ„ κ°„λ‹¨ν•˜κ²Œ κΈ°λ‘ν•œ κΈ€μž…λ‹ˆλ‹€.
책에 λŒ€ν•œ μžμ„Έν•œ 사항은 링크λ₯Ό μ°Έκ³ ν•΄μ£Όμ„Έμš”. πŸ‘

πŸ“– 1. CSS μΆ”κ°€ κ·œμΉ™κ³Ό λ°˜μ‘ν˜• μ›Ή

CSS3둜 λ„˜μ–΄μ˜€λ©΄μ„œ λ°˜μ‘ν˜• 웹을 μœ„ν•΄ 많이 μ‚¬μš©λ˜λŠ” 것이 κ·œμΉ™(@-rule)μž…λ‹ˆλ‹€.
λ°˜μ‘ν˜• 웹을 μ‚¬μš©ν•˜μ—¬ λ°μŠ€ν¬νƒ‘ μ „μš© μ›Ή νŽ˜μ΄μ§€μ™€ λͺ¨λ°”일 μ „μš© μ›Ή νŽ˜μ΄μ§€λ₯Ό λ”°λ‘œ κ΅¬λΆ„ν•΄μ„œ λ§Œλ“€μ§€ μ•Šμ•„λ„ λ©λ‹ˆλ‹€.
μ‚¬μš©μžκ°€ μ‚¬μš©ν•˜κ³  μžˆλŠ” 기기의 μ’…λ₯˜μ— λ”°λΌμ„œ λ‹€λ₯Έ ν˜•νƒœμ˜ 화면을 λ³΄μ—¬μ£ΌλŠ” λ°©λ²•μž…λ‹ˆλ‹€.
(λ°˜μ‘ν˜• μ›Ήκ³ΌλŠ” λ°˜λŒ€λ‘œ λ”°λ‘œ λ§Œλ“œλŠ” 웹을 μ μ‘ν˜• 웹이라고 λΆ€λ¦…λ‹ˆλ‹€.)

@import κ·œμΉ™

CSS νŒŒμΌμ—μ„œ λ‹€λ₯Έ CSS νŒŒμΌμ„ μΆ”κ°€ν•˜λŠ” λ°©λ²•μž…λ‹ˆλ‹€.
link보닀 쒀더 κΉ”λ”ν•©λ‹ˆλ‹€.

<head>
  <title>Link stylesheet</title>
  <link rel="stylesheet" href="StyleSheetA.css" />
  <link rel="stylesheet" href="StyleSheetB.css" />
</head>

<!-- 🌟 μœ„μ™€ μ•„λž˜λŠ” ν‘œν˜„μ˜ 차이만 μžˆμ„ 뿐 같은 κ²°κ³Όλ₯Ό λƒ…λ‹ˆλ‹€. -->

<title>Import Query</title>
<style>
  @import url(StyleSheetA.css);
  @import url(StyleSheetB.css);

  /*🌟 일반 μŠ€νƒ€μΌ μ‚¬μš©κ³Ό 병행할 수 μžˆμŠ΅λ‹ˆλ‹€.*/

  h1 {
    background-color: gold;
  }
</style>

@font-face κ·œμΉ™

λ‘œμ»¬μ— μžˆλŠ” 폰트 νŒŒμΌμ„ 톡해 폰트λ₯Ό λ§Œλ“œλŠ” κ·œμΉ™μž…λ‹ˆλ‹€.

<style>
  @font-face {
    font-family: 'jayden'; /* 🌟 μ›ν•˜λŠ” μ΄λ¦„μœΌλ‘œ μ§€μ–΄μ€λ‹ˆλ‹€. */
    src: local('NanumGothic'), url('NanumGothic.eot'), url('NanumGothic.ttf'),
      url('NanumGothic.woff');
    /* 🌟 λ‘œμ»¬μ— μžˆλŠ” 폰트 파일 경둜λ₯Ό μ§€μ •ν•©λ‹ˆλ‹€. */
    /* 🌟 λΈŒλΌμš°μ € λ³„λ‘œ μ§€μ›ν•˜λŠ” 폰트 ν™•μž₯μžκ°€ 달라 μ—¬λŸ¬ 개의 ν™•μž₯μžκ°€ μžˆλŠ” κ²ƒμž…λ‹ˆλ‹€. */
  }

  * {
    font-family: 'jayden'; /* 🌟 지어쀀 폰트λ₯Ό μ΄λ ‡κ²Œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. */
  }
</style>

@media κ·œμΉ™

λ‹€μ–‘ν•œ μž₯μΉ˜μ—μ„œ HTML λ¬Έμ„œκ°€ μ μ ˆν•œ ν˜•νƒœλ₯Ό κ°–μΆ”κ²Œ λ§Œλ“€μ–΄μ£ΌλŠ” κ·œμΉ™μž…λ‹ˆλ‹€.
졜근 HTML νŽ˜μ΄μ§€κ°€ λ‹€μ–‘ν•œ μž₯μΉ˜μ—μ„œ μ‹€ν–‰λ˜λ©΄μ„œ μ€‘μš”ν•˜κ²Œ λΆ€κ°λœ κ·œμΉ™μž…λ‹ˆλ‹€.

<title>Media Query Basic</title>
<!-- 🌟 일반 μ›Ή νŽ˜μ΄μ§€μ—μ„  desktop.css 적용 -->
<link rel="stylesheet" href="desktop.css" media="screen" />
<!-- 🌟 μ›Ή νŽ˜μ΄μ§€ ν”„λ¦°νŠΈν•  땐 print.css 적용 -->
<link rel="stylesheet" href="print.css" media="print" />

2. media query

πŸ”₯ μ—¬κΈ°μ„œ 기쀀이 λ˜λŠ” μˆ«μžλŠ” μ•„λž˜μ™€ κ°™μŠ΅λ‹ˆλ‹€.

  • 768px : μ•„μ΄νŒ¨λ“œκ°€ 수직 μƒνƒœμΌ λ•Œμ˜ λ„ˆλΉ„μž…λ‹ˆλ‹€.
  • 960px : 일반적인 ν˜„λŒ€ μ›Ή νŽ˜μ΄μ§€μ˜ λ„ˆλΉ„μž…λ‹ˆλ‹€.
<!DOCTYPE html>
<html>
  <head>
    <title>Media Query Basic</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <style>
      /* 🌟 μ΅œλŒ€ λ„ˆλΉ„κ°€ 767px ➑️ 767px μ΄ν•˜μ—μ„  μ•„λž˜ style 적용*/
      @media screen and (max-width: 767px) {
        html {
          background: red;
          color: white;
          font-weight: bold;
        }
      }

      /* 🌟 768px 이상 959px μ΄ν•˜μ—μ„  μ•„λž˜ style 적용*/
      @media screen and (min-width: 768px) and (max-width: 959px) {
        html {
          background: green;
          color: white;
          font-weight: bold;
        }
      }

      /* 🌟 960px 이상에선 μ•„λž˜ style 적용*/
      @media screen and (min-width: 960px) {
        html {
          background: blue;
          color: white;
          font-weight: bold;
        }
      }
    </style>
  </head>
  <body>
    <h1>Lorem ipsum</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    <p>Aenean luctus congue scelerisque. Maecenas aliquet ante.</p>
  </body>
</html>

3. import query에 media query μ‚¬μš©

@import κ·œμΉ™μ—λ„ @media κ·œμΉ™μ„ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@import url(desktop.css) screen;
@import url(print.css) print;

βž•. ν™”λ©΄ λ°©ν–₯ μ „ν™˜(feat. @media)

λ―Έλ””μ–΄ 쿼리λ₯Ό μ‚¬μš©ν•˜μ—¬ κΈ°κΈ°κ°€ μˆ˜ν‰/수직 μƒνƒœμ— 따라 λ‹€λ₯Έ μŠ€νƒ€μΌμ„ μ μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
즉, μˆ˜ν‰/μˆ˜μ§μ„ ꡬ뢄할 수 μžˆμŠ΅λ‹ˆλ‹€.

<title>Media Query Basic</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
  /* 🌟 portrait : μ΄ˆμƒν™” λͺ¨λ“œ 즉, 수직으둜 μ„Έμ›Œμ Έ μžˆλŠ” 경우 */
  @media screen and (orientation: portrait) {
    html {
      background: red;
      color: white;
      font-weight: bold;
    }
  }

  /* 🌟 landscape : 풍경 λͺ¨λ“œ 즉, μˆ˜ν‰μœΌλ‘œ 놓여 μžˆλŠ” 경우 */
  @media screen and (orientation: landscape) {
    html {
      background: green;
      color: white;
      font-weight: bold;
    }
  }
</style>