DEV Community


Posted on • Updated on

Creating an online budget tool 5/5

In this article I am going to add styles to my form so that it looks visually appealing with final version looking like this:


There is still a lot of work to be performed to complete the styling phase but I want to demonstrate the techniques that I used first.

The page is styled using bootstrap and is based of the bootstrap starter form:

To style the form I have inserted a link to bootstrap styles into the page header

    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <title>My Budget</title>
    <link rel="preconnect" href="">
    <link rel="preconnect" href="" crossorigin>
    <link href="" rel="stylesheet">
    <link href="style.css" rel="stylesheet" type="text/css" />
Enter fullscreen mode Exit fullscreen mode

Note that I have also brought in a google font. These are customised fonts that you can use to make your site look a lot better.

I have added a navbar to the top of the page:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">My Budget</a>
Enter fullscreen mode Exit fullscreen mode

And I have enclosed the budget table in a container. A container is used to centre a group of elements on the page. If you want to have full width for a group of elements you use container-fluid.

    <div class="container bg-white mt-3 rounded">
      <div class="my-budget">
        <table id="budgetTable" class="table">
              <td><input placeholder="Enter item" type="text" autocomplete="off" id="newItem" class="form-control"></td>
              <td><input placeholder="Enter amount" type="number" autocomplete="off" id="newAmount" class="form-control"></td>
              <td><button id="addButton" type="button" class="btn btn-link">Add</button></td>
Enter fullscreen mode Exit fullscreen mode

I have also moved the new item form into the table so that it appears as the first row and styled the buttons using the btn btn-link class. Note as well that the container is making use of bg-white mt-3 and rounded classes which let you style an element without needing to write your own custom css.

In order to use bootstrap properly you need to include some javascript which I have placed at the bottom of the page.

    <script src="" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
Enter fullscreen mode Exit fullscreen mode

Finally I have added a small bit of css into the styles.css file to control the page fonts and backgrounds.

body {
  font-family: 'Noto Serif', serif;
  background: #D3D3D3;
Enter fullscreen mode Exit fullscreen mode

And I fixed a bug where the disabled attribute was not being cleared when the user clicked cancel.

const cancelEdit = () => {
  id = 'budgetTable';

  document.getElementById('newItem').disabled = false;
  document.getElementById('newAmount').disabled = false;
  document.getElementById('addButton').disabled = false;

  document.getElementById(id).tBodies[0].innerHTML = renderRows(budgetItems);
Enter fullscreen mode Exit fullscreen mode

What I have shown is how easy it is to add bootstrap to a form and then to style that form so that it looks nice. The code for this iteration can be found here:

Discussion (0)