dynamic table and keep the thead fixed











up vote
1
down vote

favorite












I have a dynamic table and I want to keep its head fixed when I scroll the table.
The table is as follows.What this basically does is, javascript will use the number in the input field and create any number of rows as it includes.I have used a fixed height for the table.But when the table grows more than the height given then I have to scroll to go down.Then the thead also goes up and go invisible, so any method to fix the thead is appreciated.



Note : I have gone through almost all the stuff here related to the same topic, but it doesnot seem to work for me.



HTML



<div class="container-fluid"" style="width: 90%" style="height: 90%">
<table id="tableAddResults" class="table table-hover" cellspacing="0">
<thead>
<tr>
<th scope="col">Index No</th>
<th scope="col">Correct A</th>
<th scope="col">Incorrect A</th>
<th scope="col">Total A</th>
</tr>
</thead>
<tbody>
</tbody>
</table>




JAVASCRIPT



function addRow(){

var rowcount = document.getElementById('rowcount').value;
var table = document.getElementById('tableAddResults');

for(y=0;y<rowcount;y++){
var newrow = table.insertRow();

var cell0 = newrow.insertCell(0);
var cell0Text = document.createTextNode('AT-');
cell0.appendChild(cell0Text);
cell0.setAttribute('contentEditable','true');

for(i=1;i<4;i++){
var cell = newrow.insertCell(i);
var cellText = document.createTextNode('');
cell.appendChild(cellText);
cell.setAttribute('contentEditable','true');
}
}
};


The CSS code I used is given below.



div.container-fluid{
overflow:hidden;
overflow-y: scroll;
height: 450px;


}










share|improve this question







New contributor




PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    1
    down vote

    favorite












    I have a dynamic table and I want to keep its head fixed when I scroll the table.
    The table is as follows.What this basically does is, javascript will use the number in the input field and create any number of rows as it includes.I have used a fixed height for the table.But when the table grows more than the height given then I have to scroll to go down.Then the thead also goes up and go invisible, so any method to fix the thead is appreciated.



    Note : I have gone through almost all the stuff here related to the same topic, but it doesnot seem to work for me.



    HTML



    <div class="container-fluid"" style="width: 90%" style="height: 90%">
    <table id="tableAddResults" class="table table-hover" cellspacing="0">
    <thead>
    <tr>
    <th scope="col">Index No</th>
    <th scope="col">Correct A</th>
    <th scope="col">Incorrect A</th>
    <th scope="col">Total A</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
    </table>




    JAVASCRIPT



    function addRow(){

    var rowcount = document.getElementById('rowcount').value;
    var table = document.getElementById('tableAddResults');

    for(y=0;y<rowcount;y++){
    var newrow = table.insertRow();

    var cell0 = newrow.insertCell(0);
    var cell0Text = document.createTextNode('AT-');
    cell0.appendChild(cell0Text);
    cell0.setAttribute('contentEditable','true');

    for(i=1;i<4;i++){
    var cell = newrow.insertCell(i);
    var cellText = document.createTextNode('');
    cell.appendChild(cellText);
    cell.setAttribute('contentEditable','true');
    }
    }
    };


    The CSS code I used is given below.



    div.container-fluid{
    overflow:hidden;
    overflow-y: scroll;
    height: 450px;


    }










    share|improve this question







    New contributor




    PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a dynamic table and I want to keep its head fixed when I scroll the table.
      The table is as follows.What this basically does is, javascript will use the number in the input field and create any number of rows as it includes.I have used a fixed height for the table.But when the table grows more than the height given then I have to scroll to go down.Then the thead also goes up and go invisible, so any method to fix the thead is appreciated.



      Note : I have gone through almost all the stuff here related to the same topic, but it doesnot seem to work for me.



      HTML



      <div class="container-fluid"" style="width: 90%" style="height: 90%">
      <table id="tableAddResults" class="table table-hover" cellspacing="0">
      <thead>
      <tr>
      <th scope="col">Index No</th>
      <th scope="col">Correct A</th>
      <th scope="col">Incorrect A</th>
      <th scope="col">Total A</th>
      </tr>
      </thead>
      <tbody>
      </tbody>
      </table>




      JAVASCRIPT



      function addRow(){

      var rowcount = document.getElementById('rowcount').value;
      var table = document.getElementById('tableAddResults');

      for(y=0;y<rowcount;y++){
      var newrow = table.insertRow();

      var cell0 = newrow.insertCell(0);
      var cell0Text = document.createTextNode('AT-');
      cell0.appendChild(cell0Text);
      cell0.setAttribute('contentEditable','true');

      for(i=1;i<4;i++){
      var cell = newrow.insertCell(i);
      var cellText = document.createTextNode('');
      cell.appendChild(cellText);
      cell.setAttribute('contentEditable','true');
      }
      }
      };


      The CSS code I used is given below.



      div.container-fluid{
      overflow:hidden;
      overflow-y: scroll;
      height: 450px;


      }










      share|improve this question







      New contributor




      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a dynamic table and I want to keep its head fixed when I scroll the table.
      The table is as follows.What this basically does is, javascript will use the number in the input field and create any number of rows as it includes.I have used a fixed height for the table.But when the table grows more than the height given then I have to scroll to go down.Then the thead also goes up and go invisible, so any method to fix the thead is appreciated.



      Note : I have gone through almost all the stuff here related to the same topic, but it doesnot seem to work for me.



      HTML



      <div class="container-fluid"" style="width: 90%" style="height: 90%">
      <table id="tableAddResults" class="table table-hover" cellspacing="0">
      <thead>
      <tr>
      <th scope="col">Index No</th>
      <th scope="col">Correct A</th>
      <th scope="col">Incorrect A</th>
      <th scope="col">Total A</th>
      </tr>
      </thead>
      <tbody>
      </tbody>
      </table>




      JAVASCRIPT



      function addRow(){

      var rowcount = document.getElementById('rowcount').value;
      var table = document.getElementById('tableAddResults');

      for(y=0;y<rowcount;y++){
      var newrow = table.insertRow();

      var cell0 = newrow.insertCell(0);
      var cell0Text = document.createTextNode('AT-');
      cell0.appendChild(cell0Text);
      cell0.setAttribute('contentEditable','true');

      for(i=1;i<4;i++){
      var cell = newrow.insertCell(i);
      var cellText = document.createTextNode('');
      cell.appendChild(cellText);
      cell.setAttribute('contentEditable','true');
      }
      }
      };


      The CSS code I used is given below.



      div.container-fluid{
      overflow:hidden;
      overflow-y: scroll;
      height: 450px;


      }







      javascript html css






      share|improve this question







      New contributor




      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 10 at 17:56









      PrabodD.

      61




      61




      New contributor




      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      PrabodD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          You can do this purly with css using position: sticky like the following. You can then change top to tell it how far it needs to be from the top to start becoming sticky.




          A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.







          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>








          share|improve this answer























          • it does the job, but it make the head transparent
            – PrabodD.
            Nov 10 at 18:03










          • I fixed that, with just some basic css
            – Get Off My Lawn
            Nov 10 at 18:04












          • that works fine
            – PrabodD.
            Nov 10 at 18:05










          • What is the meaning of thead > tr > th
            – PrabodD.
            Nov 11 at 2:40










          • The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
            – Get Off My Lawn
            Nov 11 at 18:52











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          PrabodD. is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241840%2fdynamic-table-and-keep-the-thead-fixed%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          You can do this purly with css using position: sticky like the following. You can then change top to tell it how far it needs to be from the top to start becoming sticky.




          A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.







          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>








          share|improve this answer























          • it does the job, but it make the head transparent
            – PrabodD.
            Nov 10 at 18:03










          • I fixed that, with just some basic css
            – Get Off My Lawn
            Nov 10 at 18:04












          • that works fine
            – PrabodD.
            Nov 10 at 18:05










          • What is the meaning of thead > tr > th
            – PrabodD.
            Nov 11 at 2:40










          • The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
            – Get Off My Lawn
            Nov 11 at 18:52















          up vote
          1
          down vote













          You can do this purly with css using position: sticky like the following. You can then change top to tell it how far it needs to be from the top to start becoming sticky.




          A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.







          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>








          share|improve this answer























          • it does the job, but it make the head transparent
            – PrabodD.
            Nov 10 at 18:03










          • I fixed that, with just some basic css
            – Get Off My Lawn
            Nov 10 at 18:04












          • that works fine
            – PrabodD.
            Nov 10 at 18:05










          • What is the meaning of thead > tr > th
            – PrabodD.
            Nov 11 at 2:40










          • The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
            – Get Off My Lawn
            Nov 11 at 18:52













          up vote
          1
          down vote










          up vote
          1
          down vote









          You can do this purly with css using position: sticky like the following. You can then change top to tell it how far it needs to be from the top to start becoming sticky.




          A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.







          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>








          share|improve this answer














          You can do this purly with css using position: sticky like the following. You can then change top to tell it how far it needs to be from the top to start becoming sticky.




          A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.







          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>








          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>





          thead > tr > th {
          position: sticky;
          top: 0;
          background: white;
          }


          table {width: 100%;}

          <div class="container-fluid" style="width: 90%" style="height: 90%">
          <table id="tableAddResults" class="table table-hover" cellspacing="0">
          <thead>
          <tr>
          <th scope="col">Index No</th>
          <th scope="col">Correct A</th>
          <th scope="col">Incorrect A</th>
          <th scope="col">Total A</th>
          </tr>
          </thead>
          <tbody>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          <tr><td>test</td><td>test</td><td>test</td><td>test</td></tr>
          </tbody>
          </table>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 18:06

























          answered Nov 10 at 18:01









          Get Off My Lawn

          12.8k1676162




          12.8k1676162












          • it does the job, but it make the head transparent
            – PrabodD.
            Nov 10 at 18:03










          • I fixed that, with just some basic css
            – Get Off My Lawn
            Nov 10 at 18:04












          • that works fine
            – PrabodD.
            Nov 10 at 18:05










          • What is the meaning of thead > tr > th
            – PrabodD.
            Nov 11 at 2:40










          • The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
            – Get Off My Lawn
            Nov 11 at 18:52


















          • it does the job, but it make the head transparent
            – PrabodD.
            Nov 10 at 18:03










          • I fixed that, with just some basic css
            – Get Off My Lawn
            Nov 10 at 18:04












          • that works fine
            – PrabodD.
            Nov 10 at 18:05










          • What is the meaning of thead > tr > th
            – PrabodD.
            Nov 11 at 2:40










          • The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
            – Get Off My Lawn
            Nov 11 at 18:52
















          it does the job, but it make the head transparent
          – PrabodD.
          Nov 10 at 18:03




          it does the job, but it make the head transparent
          – PrabodD.
          Nov 10 at 18:03












          I fixed that, with just some basic css
          – Get Off My Lawn
          Nov 10 at 18:04






          I fixed that, with just some basic css
          – Get Off My Lawn
          Nov 10 at 18:04














          that works fine
          – PrabodD.
          Nov 10 at 18:05




          that works fine
          – PrabodD.
          Nov 10 at 18:05












          What is the meaning of thead > tr > th
          – PrabodD.
          Nov 11 at 2:40




          What is the meaning of thead > tr > th
          – PrabodD.
          Nov 11 at 2:40












          The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
          – Get Off My Lawn
          Nov 11 at 18:52




          The > Means that the next item must be a direct child. So tr must be a direct child of thead and th must be a direct child of tr. developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
          – Get Off My Lawn
          Nov 11 at 18:52










          PrabodD. is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          PrabodD. is a new contributor. Be nice, and check out our Code of Conduct.













          PrabodD. is a new contributor. Be nice, and check out our Code of Conduct.












          PrabodD. is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241840%2fdynamic-table-and-keep-the-thead-fixed%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python