๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[๊ฐœ๋ฐœ] Practice/Node.js MongoDB

[Node.js / MongoDB] Bootstrap ์„ ์ด์šฉํ•ด ๋น ๋ฅด๊ฒŒ UI ๊ฐœ๋ฐœํ•ด๋ณด๊ธฐ

by Connecting-the-dots 2022. 3. 11.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ก ์‹ค์Šต ํฌ์ธํŠธ!

  • Node.js / MongoDB ๊ฐ•์˜๊ฐ€ HTML / CSS ๋ฅผ ์ค‘์ ์ ์œผ๋กœ ๋‹ค๋ฃจ๋Š” ์ˆ˜์—…์ด ์•„๋‹ˆ๋ฏ€๋กœ, Bootstrap ์„ ์ด์šฉํ•˜์—ฌ ๊ธฐ๋ณธ์ ์ธ ๊ตฌ์กฐ๋ฅผ ๋‹ค๋“ฌ๋Š” ๊ฒƒ๋งŒ ๋น ๋ฅด๊ฒŒ ์ง„ํ–‰ํ–ˆ๋‹ค.

๐Ÿ’œ Bootstrap ์œผ๋กœ ๊ธ€์“ฐ๊ธฐ ํŽ˜์ด์ง€(write.html) ๋งŒ๋“ค๊ธฐ

  • ์šฐ์„ , ๋ณธ๊ฒฉ์ ์œผ๋กœ ๋ ˆ์ด์•„์›ƒ์„ ๋งŒ๋“ค๊ธฐ ์ „์— Bootstrap ์—์„œ starter template ์„ ๋จผ์ € ๋ณต์‚ฌํ•ด์™€์„œ html ํŒŒ์ผ์— ๋ถ™์—ฌ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.
  • ์ดํ›„, Bootstrap ์˜ Navbar ์–‘์‹๊ณผ form ์–‘์‹์„ ์ด์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ ๋ ˆ์ด์•„์›ƒ์„ ๋งŒ๋“ค์—ˆ๋‹ค.

๐Ÿค Navbar ๋งŒ๋“ค๊ธฐ

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="/">Todo App</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="/">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="/write">Write</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">์ž„์‹œ</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

๐Ÿค ๊ธ€์“ฐ๊ธฐ form ๋งŒ๋“ค๊ธฐ

<h4 class="container mt-5"><strong>๊ธ€์“ฐ๊ธฐ</strong></h4>
<div class="container mt-4">
  <form>
    <div class="form-group my-4">
      <label class="mb-2">์˜ค๋Š˜์˜ ํ• ์ผ</label>
      <input type="text" class="form-control">
    </div>
    <div class="form-group my-4">
      <label class="mb-2">๋‚ ์งœ</label>
      <input type="text" class="form-control">
    </div>
    <button type="submit" class="btn btn-danger fw-bold">Submit</button>
  </form>
</div>

๐Ÿ’œ JavaScript ์ž‘์„ฑํ•˜๊ธฐ

app.get('/write', function(req, res){
    res.sendFile(__dirname + '/write.html');
});
  • ์„œ๋ฒ„์—์„œ HTML ํŒŒ์ผ์ „์†กํ•ด๋ณด๋Š” ์‹ค์Šต์„ ํ•  ๋•Œ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ ์–‘์‹ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋˜, ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •ํ•ด์ฃผ์—ˆ๋‹ค.
728x90
๋ฐ˜์‘ํ˜•