title: Errors with freeze table header - HTML
body: <p>I am trying to enter entries in table inputs for my inventory website. I want to freeze the headers of each column and tried doing it with this -&gt; <a href="https://stackoverflow.com/questions/8423768/freeze-the-top-row-for-an-html-table-only-fixed-table-header-scrolling">Freeze the top row for an html table only (Fixed Table Header Scrolling)</a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>window.onload = function(){
    var to_show = '';
    for(var i = 1 ; i &lt; 50 ; i++){
      to_show += '&lt;tr&gt;&lt;td&gt;&lt;input type="text" autocomplete="off" id="product_name_'+ i +'" name="product_name_'+i+'" onkeyup="productSearch(this.value, '+i+')" tabindex="-1" style="font-size:larger;"&gt;&lt;/td&gt;';
      to_show += '&lt;td&gt;&lt;input type="text" autocomplete="off" id="location_'+ i +'" name="location_'+ i +'" onkeyup="productSearch(this.value, '+ i +')" tabindex="-1" style="font-size:larger;"&gt;&lt;/td&gt;&lt;/tr&gt;';
    }
    document.getElementById('addInside_tr_20').innerHTML = to_show;
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>@import url("https://fonts.googleapis.com/css?family=Montserrat:300,400|Oswald:200,300,400&amp;display=swap");
  :root {
    --purple-theme: #091428;
    --lightpurple-theme: #0f3a41;
    --gray-bg-heading: #b8b8b8;
    --gray-bg-sidebar: #dee3e7;
    --lightgreen-theme: #65ffce;
    --green-theme: #46b692;
    --red-theme: #f75b54;
  }
  /* width */
  ::-webkit-scrollbar {
    width: 10px;
  }
  /* Track */
  ::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px grey;
    border-radius: 0px 0px 10px 10px;
    background: var(--lightpurple-theme);
  }
  /* Handle */
  ::-webkit-scrollbar-thumb {
    background: var(--green-theme);
    border-radius: 0 0 10px 10px;
  }
  /* Handle on hover */
  ::-webkit-scrollbar-thumb:hover {
    background: var(--lightgreen-theme);
  }
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  ::-moz-selection {
    /* Code for Firefox */
    color: var(--purple-theme);
    background: var(--green-theme);
  }
  ::selection {
    color: var(--purple-theme);
    background: var(--green-theme);
  }
  input:focus,
  option:focus,
  select:focus {
    outline-color: var(--lightgreen-theme);
  }
  body {
    height: 100%;
    background-repeat: no-repeat;
  }
  a {
    text-decoration: none;
  }
  table,
  select,
  input,
  a {
    color: whitesmoke;
  }
  input {
    width: 100%;
    line-height: 5px;
    font-size: 10px;
  }
  input[type="text"],
  input[type="url"],
  input[type="number"] {
    height: 30px;
    border: 1px solid var(--green-theme);
    background-color: transparent;
    color: whitesmoke;
    font-size: 15px;
  }
  input[type="button"],
  input[type="reset"],
  input[type="submit"] {
    border: 1px solid var(--green-theme);
    background-color: var(--green-theme);
    color: var(--purple-theme);
    text-decoration-style: bold;
    font-size: 15px;
    border-radius: 0px 15px 15px 0px;
  }
  
  /* ------grid container------ */
  input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
  }
  input[type="date"] {
    height: 100%;
  }
  .grid_container {
    display: grid;
    grid-template-columns: repeat(auto, 1fr);
    grid-gap: 10px;
    padding: 10px;
    margin: 0 auto;
    color: whitesmoke;
  }
  .grid {
    background-color: var(--purple-theme);
    border: 1px solid lightgrey;
    padding: 20px;
  }
  .inside &gt; span {
    font-family: "Oswald", sans-serif;
    font-weight: 400;
    font-size: 18px;
  }
  .item1 {
    grid-column: 1 / 3;
  }
  .item2 {
    grid-column: 3 / 5;
  }
  
  .item3 {
    grid-column: 5 / 7;
  }
  .item4 {
    grid-column: 7 / 9;
  }
  
  .item5 {
    grid-column: 1 / 9;
  }
  
  .inside {
    padding: 0;
    padding-bottom: 10px;
    border: none;
  }
  
  .item2 {
    grid-column: 1 / 9;
    grid-row: 1 / 5;
  }
  .inside input[type="text"] {
    width: 200px;
  }
  .item2 select,
  .item2 option {
    width: 100%;
    height: 30px;
    background-color: var(--purple-theme);
    border: 1px solid var(--green-theme);
    text-align: center;
  }
  .item2 select option {
    background: var(--purple-theme);
  }
  .item2 table {
    width: 100%;
    text-align: center;
    margin-top: 20px;
    font-size: 20px;
  }
  .details table:nth-child(1) {
    margin-top: -20px;
  }
  .details {
    margin-top: -20px;
  }
  .item2 th {
    background-color: var(--green-theme);
    color: var(--purple-theme);
    padding: 15px;
  }
  .item2 a {
    text-decoration: underline;
  }
  
  /* main edit here start */
                        #text-area td:nth-child(1) {
                          width: 80%;
                        }
                        #text-area td:nth-child(2) {
                          width: 20%;
                        }
                        #text-area thead th:nth-child(1) {
                          width: 80%;
                        }
                        #text-area thead th:nth-child(2) {
                          width: 20%;
                        }
  
                        #text-area thead {
                          display: block;
                        }
                        #text-area tbody {
                          height: 440px;
                          display: block;
                          overflow: auto;
                          width: 100%;
                        }
                        #text-area input {
                          width: 100%;
                        }
  
                        #text-area input {
                          border: none;
                        }
                        #text-area {
                          border: 1px solid var(--green-theme);
                        }
                        #text-area tr:nth-child(2n + 1) {
                          background: var(--lightpurple-theme);
                        }
                        #text-area td:nth-child(4) {
                          border-right: none;
                        }
                        #text-area td {
                          border-right: 1px solid var(--green-theme);
                        }
  /* main edit here ends */
  .item2 .inside table * {
    padding-bottom: 20px;
  }
  
  .suggestion {
    position: absolute;
    background-color: var(--purple-theme);
    font-size: smaller;
    cursor: pointer;
  }
  .suggestion_i:hover {
    color: var(--purple-theme);
    background-color: var(--green-theme);
  }
  .suggestion_i {
    cursor: pointer;
    text-align: center;
    text-justify: center;
    padding: 10px 10px -5px 10px;
  }
  #sorted_div {
    background-color: var(--purple-theme);
    /*position:absolute;*/
    top: 123px;
  }
  #sorted_div tr:nth-child(2n + 1) {
    background: var(--lightpurple-theme);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>        &lt;div class="grid_container"&gt;
            &lt;div class="grid item2"&gt;
              &lt;div class="inside" id="topTableID"&gt;
                &lt;form action="php/invoiceFetch.php" method="post" enctype="multipart/form-data" id='myForm' onkeypress="return event.keyCode != 13;"&gt;
                  &lt;table&gt;
                    &lt;tr&gt;
                      &lt;td&gt;&lt;label for=""&gt;Location :&lt;/label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" autocomplete="off" name="invoice_name" id="invoice_name" onchange="invoiceSpliter()" onkeyup="customerSearch(this.value)" style="width: 500;"&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;label&gt;Product Suggestion : &lt;/label&gt;&lt;/td&gt;
                      &lt;td&gt;
                        &lt;div id="product_suggestion" class="suggestion"&gt;&lt;/div&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                      &lt;td&gt;
                        &lt;div id="suggestion" class="suggestion"&gt;&lt;/div&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
  
              &lt;div class="details"&gt;
                &lt;table id="text-area"&gt;
                  &lt;thead&gt;
                    &lt;tr&gt;
                      &lt;th&gt;&lt;label&gt;Product Name&lt;/label&gt;&lt;/th&gt;
                      &lt;th&gt;&lt;label&gt;Current Locations&lt;/label&gt;&lt;/th&gt;
                    &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody id="addInside_tr_20"&gt;
                      &lt;!--there will be some rows added here --&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
                &lt;table&gt;
                  &lt;tr&gt;
                    &lt;td&gt;&lt;input type="reset" value="Reset" tabindex="-1"&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;input type="button" onclick="document.getElementById('myModal').style.display = 'block';" value="Submit"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;/table&gt;
                &lt;/form&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <hr />
  <h2>You can check the code on [codepen]{https://codepen.io/zaidi2293/pen/WNwmJrP} (Ignore most of the css as they are just to replicate what I had so that I don't miss something out)</h2>
  <hr />
  <p>(Sorry for the extensive code length) The Problem is the &quot;thead&quot; is not aligned with &quot;tbody&quot; as in column perspective because of overflow in vertical direction. I've asked this question before but that doesn't seem to work for me. Also, there will be some more columns added in the future. <strong>No custom size width answers please</strong></p>