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

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

πŸ“– 1. Appendix A - λΆ€νŠΈμŠ€νŠΈλž©

λΆ€νŠΈμŠ€νŠΈλž©μ€ νŠΈμœ„μΉ˜μ—μ„œ μ œκ³΅ν•˜λŠ” μ›Ή νŽ˜μ΄μ§€ λ””μžμΈ ν”„λ ˆμž„μ›Œν¬μž…λ‹ˆλ‹€. λΆ€νŠΈμŠ€νŠΈλž©μ„ μ‚¬μš©ν•˜μ—¬ λ°˜μ‘ν˜• μ›Ή νŽ˜μ΄μ§€λ₯Ό 쉽고 λΉ λ₯΄κ²Œ λ§Œλ“€ 수 μžˆμŠ΅λ‹ˆλ‹€.
λΆ€νŠΈμŠ€νŠΈλž©μ€ 2가지 λ°©λ²•μœΌλ‘œ μ œκ³΅λ©λ‹ˆλ‹€.

  1. μžλ°”μŠ€ν¬λ¦½νŠΈμ™€ μŠ€νƒ€μΌμ‹œνŠΈ νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•΄μ„œ μ‚¬μš©
  2. CDN(Content Delivery Network)을 μ‚¬μš©

κ°œμš”

μ•„λž˜μ˜ μ½”λ“œλ₯Ό <head>에 λ„£μ–΄μ€λ‹ˆλ‹€.

<!-- CSS only -->
<!-- 🌟 head νƒœκ·Έμ— λ‘‘λ‹ˆλ‹€. -->
<link
  href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css"
  rel="stylesheet"
  integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx"
  crossorigin="anonymous"
/>
<!-- JavaScript Bundle with Popper -->
<!-- 🌟 body νƒœκ·Έ 끝에 λ‘‘λ‹ˆλ‹€. -->
<script
  src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"
  integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa"
  crossorigin="anonymous"
></script>

λ ˆμ΄μ•„μ›ƒ

1. Fixed λ ˆμ΄μ•„μ›ƒ

κ³ μ •λœ λ„ˆλΉ„λ₯Ό μ‚¬μš©ν•˜λŠ” λ ˆμ΄μ•„μ›ƒμž…λ‹ˆλ‹€. ν™”λ©΄μ˜ 크기λ₯Ό 바꿔도 μ»¨ν…μΈ μ˜ 크기가 λ³€ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같이 classλ₯Ό β€œcontainerβ€λ‘œ 지정해주면 fixed λ ˆμ΄μ•„μ›ƒμ΄ λ§Œλ“€μ–΄μ§‘λ‹ˆλ‹€.
λ˜ν•œ, λΆ€νŠΈμŠ€νŠΈλž©μ˜ κΈ°λ³Έ ν™”λ©΄ λ„ˆλΉ„λŠ” 960px이고 λ„ˆλΉ„κ°€ κ·Έ μ•„λž˜λ‘œ 쀄어듀면 λ°˜μ‘ν˜• μ›Ή νŽ˜μ΄μ§€λ‘œ λ™μž‘ν•©λ‹ˆλ‹€.

μ—¬κΈ°μ„œ 정적(Fixed) vs 동적(Fluid)와 λ°˜μ‘ν˜•μ€ λ‹€λ₯Έ κ°œλ…μž…λ‹ˆλ‹€. λ°˜μ‘ν˜•μ€ νŠΉμ • ν™”λ©΄ 크기에 λŒ€ν•΄μ„œ λ‹€λ₯Έ λ ˆμ΄μ•„μ›ƒμ„ κ°–κ²Œ κ΅¬μ„±ν•œ κ²ƒμž…λ‹ˆλ‹€. λ°˜μ‘ν˜•μ˜ λ°˜λŒ€λŠ” μ μ‘ν˜•μž…λ‹ˆλ‹€.(μ°Έκ³  : ch 11)

<div class="container">
  <h1>Lorem ipsum</h1>
</div>

2. Fluid λ ˆμ΄μ•„μ›ƒ

νŠΉμ • ν™”λ©΄ 크기에 따라 λ ˆμ΄μ•„μ›ƒ 크기가 λ³€ν™”ν•©λ‹ˆλ‹€. ν™”λ©΄μ˜ 크기λ₯Ό λ°”κΎΈλ©΄ μ»¨ν…μΈ μ˜ 크기가 λ³€ν•©λ‹ˆλ‹€.

<div class="container-fluid">
  <h1>Lorem ipsum</h1>
</div>

νˆ΄λ°”

μ›Ή νŽ˜μ΄μ§€ 상단에 μœ„μΉ˜ν•˜λŠ” ꡬ성 μš”μ†Œμž…λ‹ˆλ‹€.

μΌλ°˜ν˜• νˆ΄λ°”

μŠ€ν¬λ‘€μ„ 내렸을 λ•Œ 보이지 μ•ŠλŠ” νˆ΄λ°”μž…λ‹ˆλ‹€. κ·Έλƒ₯ 일반 div처럼 슀크둀 μ‹œ μœ„λ‘œ μ˜¬λΌκ°‘λ‹ˆλ‹€.

<div class="navbar navbar-dark bg-dark">
  <div class="container">
    <a class="navbar-brand" href="#">Bootstrap</a>
  </div>
</div>

κ³ μ •ν˜• νˆ΄λ°”

μŠ€ν¬λ‘€μ„ 내렸을 λ•Œ λ”°λΌμ˜€λŠ” νˆ΄λ°”μž…λ‹ˆλ‹€. 즉, 상단에 계속 κ³ μ •λ˜μ–΄μžˆμŠ΅λ‹ˆλ‹€.

<!-- 🌟 fixed-top: κ³ μ •ν˜• νˆ΄λ°”λ₯Ό λ§Œλ“­λ‹ˆλ‹€.-->
<!-- 🌟 navbar-expand-lg: λ°˜μ‘ν˜• νˆ΄λ°”λ₯Ό λ§Œλ“­λ‹ˆλ‹€.-->

<div class="navbar navbar-dark bg-dark fixed-top navbar-expand-lg">
  <div class="container">
    <a class="navbar-brand" href="#">Bootstrap</a>
  </div>
</div>

일반적으둜 νˆ΄λ°”λ₯Ό μ μš©ν•˜λ©΄ νˆ΄λ°”κ°€ 곡간을 μ°¨μ§€ν•˜κ²Œ λ©λ‹ˆλ‹€. λ”°λΌμ„œ μ•„λž˜μ™€ 같은 처리λ₯Ό ν•΄μ€λ‹ˆλ‹€.

body {
  padding-top: 70px;
}

μΆ”κ°€(νˆ΄λ°” λ²„νŠΌ)

<body>
  <div class="navbar navbar-dark bg-dark fixed-top navbar-expand-lg">
    <div class="container">
      <a class="navbar-brand" href="#">Bootstrap</a>
      <!-- 🌟 button νƒœκ·Έμ— data-target="#navbar-content"λ₯Ό 톡해
       id="navbar-content"인 νƒœκ·Έλ₯Ό λ²„νŠΌμ„ 톡해 μ—΄κ³  닫을 λŒ€μƒμœΌλ‘œ μ§€μ •ν•©λ‹ˆλ‹€. -->
      <button
        class="navbar-toggler"
        type="button"
        data-toggle="collapse"
        data-target="#navbar-content"
      >
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbar-content">
        <!-- 🌟  mr-auto은 margin-auto의 의미둜 κ·Έ λ‹€μŒ ul을 λ’€λ‘œ λ°€μ–΄λ²„λ¦¬κ²Œ λ©λ‹ˆλ‹€. -->
        <ul class="navbar-nav mr-auto">
          <!-- 🌟 μ‹œμž‘: class에 dropdown을 μΆ”κ°€ν•˜κ³  κ·Έ μ•„λž˜ ν† κΈ€λ²„νŠΌμ„ 톡해 λ“œλ‘­λ‹€μš΄ μ•„μ΄ν…œμ„ λ§Œλ“­λ‹ˆλ‹€. -->
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown">HTML</a>
            <div class="dropdown-menu">
              <a class="dropdown-item" href="#">Geolocation</a>
              <a class="dropdown-item" href="#">Drag and Drop</a>
              <div class="dropdown-divider"></div>
              <a class="dropdown-item" href="#">Motion</a>
            </div>
          </li>
          <!-- 🌟 끝: class에 dropdown을 μΆ”κ°€ν•˜κ³  κ·Έ μ•„λž˜ ν† κΈ€λ²„νŠΌμ„ 톡해 λ“œλ‘­λ‹€μš΄ μ•„μ΄ν…œμ„ λ§Œλ“­λ‹ˆλ‹€. -->
          <li class="nav-item"><a class="nav-link" href="#">CSS3</a></li>
          <li class="nav-item"><a class="nav-link" href="#">ECMAScript5</a></li>
          <li class="nav-item"><a class="nav-link" href="#">Node.js</a></li>
          <li class="nav-item"><a class="nav-link" href="#">API</a></li>
        </ul>
        <!-- 🌟 μ΄λ ‡κ²Œ μž…λ ₯ ν˜•μ‹μ„ κ°„λ‹¨ν•˜κ²Œ λ§Œλ“€ 수 μžˆμŠ΅λ‹ˆλ‹€. -->
        <form class="form-inline">
          <input type="text" class="form-control" placeholder="Search" />
        </form>
        <ul class="nav navbar-nav navbar-right">
          <li class="nav-item"><a class="nav-link" href="#">Node.js</a></li>
          <li class="nav-item"><a class="nav-link" href="#">API</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div class="container">
    <h1>Jayden</h1>
    <p>μ•ˆλ…•ν•˜μ„Έμš”</p>
    <p>λ°˜κ°‘μŠ΅λ‹ˆλ‹€</p>
    <p>개발자</p>
    <p>ν”„λ‘ νŠΈμ—”λ“œ</p>
    <p>λ§Œμ„Έμž…λ‹ˆλ‹€</p>
  </div>
</body>

πŸ“• λΆ€νŠΈμŠ€νŠΈλž© 정리

λΆ€νŠΈμŠ€νŠΈλž©μ€ μ›Ή νŽ˜μ΄μ§€ λ””μžμΈ ν”„λ ˆμž„μ›Œν¬λ‘œ κ°„νŽΈν•˜κ²Œ μ›Ή νŽ˜μ΄μ§€λ₯Ό λ§Œλ“€κΈ° μ’‹μŠ΅λ‹ˆλ‹€. λ‹€λ§Œ, 그만큼 λ‹€μ†Œ 무겁고 μ •ν˜•ν™”λœ νŽ˜μ΄μ§€λ₯Ό λ§Œλ“€μ–΄λ‚Έλ‹€λŠ” 단점도 μžˆμŠ΅λ‹ˆλ‹€.
λΆ€νŠΈμŠ€νŠΈλž©μ€ κ·Έ λ‚΄μš©μ„ ν•˜λ‚˜ν•˜λ‚˜ μ™Έμš°κ³  ν•˜κΈ°λ³΄λ‹¨ λΆ€νŠΈμŠ€νŠΈλž© κ³΅μ‹λ¬Έμ„œλ₯Ό λ³΄λ©΄μ„œ ν•„μš”ν•œ κΈ°λŠ₯듀을 κ΅¬ν˜„ν•˜λŠ” 게 μ’‹μŠ΅λ‹ˆλ‹€.

πŸ“– 2. Appendix B - Less μŠ€νƒ€μΌμ‹œνŠΈ

μŠ€νƒ€μΌμ‹œνŠΈλ₯Ό 더 μ‰½κ²Œ μ‚¬μš©ν•˜κΈ° μœ„ν•΄ λ‹€μ–‘ν•œ μŠ€νƒ€μΌμ‹œνŠΈ 엔진듀이 λ“±μž₯ν–ˆμŠ΅λ‹ˆλ‹€.
μŠ€νƒ€μΌμ‹œνŠΈ 엔진은 νŠΉμ •ν•œ ν˜•νƒœμ˜ μŠ€νƒ€μΌμ‹œνŠΈλ₯Ό CSS μŠ€νƒ€μΌμ‹œνŠΈλ‘œ λ³€κ²½ν•΄μ£ΌλŠ” λ³€ν™˜ μ—”μ§„μ»΄νŒŒμΌλŸ¬μž…λ‹ˆλ‹€.
λŒ€ν‘œμ μœΌλ‘œ Sass 엔진과 Less 엔진이 μžˆμŠ΅λ‹ˆλ‹€.

κ°œμš”

Less 곡식 ν™ˆνŽ˜μ΄μ§€μ—μ„œ less.js νŒŒμΌμ„ λ°›μŠ΅λ‹ˆλ‹€.
μ΄μ–΄μ„œ html 파일과 less ν™•μž₯자λ₯Ό μ“°λŠ” νŒŒμΌμ„ μƒμ„±ν•΄μ€λ‹ˆλ‹€. 그럼 μ•„λž˜μ™€ 같이 파일이 μ€€λΉ„λ©λ‹ˆλ‹€.

  • less-1.3.0.min.js(less ν™ˆνŽ˜μ΄μ§€μ—μ„œ 받은 파일) -> λ³€ν™˜ 엔진 μ—­ν• 
  • index.html
  • LessStyleSheet.less(마치 style.css처럼 μŠ€νƒ€μΌμ„ 적을 νŒŒμΌμž…λ‹ˆλ‹€.)
<head>
  <title>Less StyleSheet Basic</title>
  <link rel="stylesheet/less" type="text/css" href="LessStyleSheet.less" />
  <script src="less-1.3.0.min.js"></script>
</head>

LessStyleSheet.less μ˜ˆμ œμž…λ‹ˆλ‹€.

// 🌟 javascript와 같이 `/` 2개둜 주석을 μ“Έ 수 μžˆμŠ΅λ‹ˆλ‹€.(였예)
// 🌟 μ„ νƒμž 내뢀에 μ„ νƒμžκ°€ μ‘΄μž¬ν•©λ‹ˆλ‹€. 쑰금 λ‚―μ„€μ§€λ§Œ 훨씬 가독성이 쒋은 κ±Έ μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€.
header {
  width: 800px;
  margin: 0 auto;

  hgroup {
    h1 {
      color: red;
    }

    h2 {
      color: blue;
    }
  }

  nav {
    ul {
      overflow: hidden;
    }

    li {
      float: left;
    }
  }
}

Less 컴파일러

μœ„μ˜ κ΅¬μ„±μ²˜λŸΌ λ³€ν™˜ 엔진 역할을 ν•˜λŠ” Less.js 파일이 νŽΈλ¦¬ν•˜κΈ΄ ν•˜μ§€λ§Œ, ꡳ이 μœ μ €μ—κ²ŒκΉŒμ§€ μ „λ‹¬ν•˜λ©΄μ„œ νŠΈλž˜ν”½μ„ λ‚­λΉ„ν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.
ν•΄μ„œ 온라인 Less μ»΄νŒŒμΌλŸ¬μ—μ„œ less ν˜•μ‹μ„ css ν˜•μ‹μœΌλ‘œ λ°”κΏ”μ„œ κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€.(곡식 ν™ˆνŽ˜μ΄μ§€μ—μ„œλ„ κ°€λŠ₯ν•©λ‹ˆλ‹€.)

κΈ°λ³Έ

λ³€μˆ˜

Less μŠ€νƒ€μΌμ‹œνŠΈλŠ” λ³€μˆ˜λ₯Ό λ§Œλ“€ 수 μžˆμŠ΅λ‹ˆλ‹€. λ³€μˆ˜λŠ” @ 기호λ₯Ό μ‚¬μš©ν•˜λ©° μŠ€νƒ€μΌμ‹œνŠΈμ—μ„œ μ‚¬μš©ν•˜λŠ” λͺ¨λ“  λ‹¨μœ„λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@margin: 10px;
@padding: 10px;
@width: 200px;

div {
  width: @width - (@padding * 2);
  padding: @padding;
  margin: @margin;
}

λ‚΄μž₯ μ„ νƒμž

μ„ νƒμž(A) λ‚΄λΆ€ μ„ νƒμž(B)κ°€ μžˆμ„ λ•Œ, A의 λ‚΄λΆ€μ—μ„œ 본인을 κ°€λ¦¬ν‚€λŠ” μ„ νƒμžκ°€ λ‚΄μž₯ μ„ νƒμžμ΄κ³  &둜 ν‘œν˜„ν•©λ‹ˆλ‹€.

div {
  background: black;
  &:hover {
    background: white;
  }

  a {
    background: red;
    color: white;
    &:hover {
      background: blue;
    }
    &:active {
      background: green;
    }
  }
}

λ‚΄μž₯ ν•¨μˆ˜

Less μŠ€νƒ€μΌμ‹œνŠΈμ—λŠ” λ‚΄μž₯ ν•¨μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. 잘 μ‚¬μš©ν•˜λ©΄ ꡉμž₯히 μœ μš©ν•˜μ§€λ§Œ, μ—¬κΈ°μ—μ„œλŠ” λ”°λ‘œ μ •λ¦¬ν•˜μ§€ μ•Šκ² μŠ΅λ‹ˆλ‹€. 🌡
Less λ‚΄μž₯ ν•¨μˆ˜ κ³΅μ‹λ¬Έμ„œλ₯Ό μ°Έκ³ ν•΄μ£Όμ„Έμš”.

믹슀인

기본적인 λ‚΄μž₯ ν•¨μˆ˜λ„ μžˆμ§€λ§Œ, μš°λ¦¬κ°€ 직접 ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄ μ‚¬μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€!(μ˜€λ§ˆμ΄κ°“ πŸ™€)
.이름(@λ³€μˆ˜1, @λ³€μˆ˜2, ...) {} ν˜•νƒœλ‘œ ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄ μ‚¬μš©ν•©λ‹ˆλ‹€.

.linearGradient(@start, @end) {
  background: @start;
  background: -moz-linear-gradient(top, @start 0%, @end 100%);
  background: -webkit-linear-gradient(top, @start 0%, @end 100%);
  background: -o-linear-gradient(top, @start 0%, @end 100%);
  background: -ms-linear-gradient(top, @start 0%, @end 100%);
  background: linear-gradient(top, @start 0%, @end 100%);
}

.button(@width, @height, @radius) {
  width: @width;
  height: @height;
  line-height: @height;
  text-align: center;
  border-radius: @radius;
}

* {
  margin: 0;
  padding: 0;
}
div {
  margin: 10px;
  float: left;

  &:nth-child(1) {
    .linearGradient(#0094ff, #004f89);
    .button(200px, 100px, 10px);
  }

  &:nth-child(2) {
    .linearGradient(#0094ff + #CC0000, #004f89 + #CC0000);
    .button(200px, 100px, 10px);
  }

  &:nth-child(3) {
    .linearGradient(#0094ff + #FF0000, #004f89 + #FF0000);
    .button(200px, 100px, 10px);
  }
}

λ˜ν•œ, μžλ£Œν˜•μ„ ν™•μΈν•˜λŠ” λ‚΄μž₯ν•¨μˆ˜λ₯Ό μ΄μš©ν•˜μ—¬ 주어진 λ³€μˆ˜κ°€ μ›ν•˜λŠ” μžλ£Œν˜•μΌ λ•Œλ§Œ ν•¨μˆ˜κ°€ μ‹€ν–‰λ˜κ²Œ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

.linearGradient(@start, @end) when (iscolor(@start)) and (iscolor(@end)) {
  background: @start;
  background: -moz-linear-gradient(top, @start 0%, @end 100%);
  background: -webkit-linear-gradient(top, @start 0%, @end 100%);
  background: -o-linear-gradient(top, @start 0%, @end 100%);
  background: -ms-linear-gradient(top, @start 0%, @end 100%);
  background: linear-gradient(top, @start 0%, @end 100%);
}

.max (@a, @b) when (@a > @b) {
  width: @a;
}
.max (@a, @b) when (@a < @b) {
  width: @b;
}

.min (@a, @b) when (@a > @b) {
  width: @b;
}
.min (@a, @b) when (@a < @b) {
  width: @a;
}

πŸ“• Less μŠ€νƒ€μΌμ‹œνŠΈ 정리

κΈ°μ‘΄ CSS에 ν”„λ‘œκ·Έλž˜λ° 언어같은 κΈ°λŠ₯λ“€(λ³€μˆ˜, λ‚΄μž₯ ν•¨μˆ˜, 믹슀인 λ“±)을 톡해 훨씬 κ°„νŽΈν•˜κ³  κΉ”λ”ν•œ μŠ€νƒ€μΌμ‹œνŠΈλ₯Ό λ§Œλ“€ 수 있게 ν•΄μ€λ‹ˆλ‹€.
개인적으둜 이 책을 읽고 κ³΅λΆ€ν•˜λ©΄μ„œ κ°€μž₯ μ‹ κΈ°ν•˜κ²Œ κ³΅λΆ€ν•œ λ‚΄μš©μ΄μ—ˆμŠ΅λ‹ˆλ‹€. 🀩