-1

I have a table:

<table class="list-table">
  <thead><tr><th>header</th></tr></thead>
  <tbody>

   <tr><td>Single row of glorious table content</td></tr>  // Repeat me x100

  </tbody>
</table>

This table is wrapped in a div to give it a fixed height:

   <div class="col-sm-3 col-sm-offset-9" style="top:80px; bottom:20px;">

   <table>
   ...
   </table>

   </div>

Now the question: How can I use overflow:auto (or equivalent) to have the tbody contents scroll if the TR repeats exceed this fixed height?

*Note I want only the tbody (or tr contents in the tbody) to scroll, not the theador its contents *

*EDIT: UPDATE * For those interested, I ended up splitting this into two identical tables, then wrapping the table with the tbody in a overflow:auto and aligning the thead separately with a position:fixed

alias51
  • 8,178
  • 22
  • 94
  • 166

4 Answers4

1

I think this will help you a lot

In your html

    <table>
<thead><tr><th>header</th></tr></thead>
  <tbody>
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
   <tr><td>Single row</td></tr>  
  </tbody>
</table>

And in your CSS

table {width:100%; border:1px solid #000000;}
thead {background-color:#000268;color:#FFFFFF;text-align:center; position:fixed; top:0px;}
thead th { height:50px;width:1000px; text-align:center;border-width: 1px;border-style: outset;}
tbody {color:#000000;text-align:center; height:150px; overflow: scroll; margin-top:00px;}
tbody td { height:60px; border-width: 1px;border-style: outset;}

Fiddle

Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
1

Probably something like this:

<table class="list-table">
  <thead><tr><th>header</th></tr></thead>
  <tbody>
    <tr>
      <td>
        <div class="col-sm-3 col-sm-offset-9" style="top:80px; bottom:20px; height:400px;overflow-y:auto;">
          <table>
            <tr><td>Single row of glorious table content</td></tr>  // Repeat me x100
          </table>
        </div>
      </td>
    </tr>
  </tbody>

Of course, if you have multiple tds, you may have to manually set all their widths to keep them properly aligned.

Ugly fiddle demo

beercodebeer
  • 990
  • 6
  • 5
0

You could wrap it in a div.

    <table>
       <thead>...</thead>
       <tbody><tr><td>
       <div style = "overflow:auto">
         //table without the header here
       </div>
       </td></tr></tbody>
    </table>

If the innertable has no margins or padding or anything of that nature, it should look like part of the original table.

Cruncher
  • 7,641
  • 1
  • 31
  • 65
0

add style for your tbody there are overflow: auto, overflow-x:scroll, overflow-y:scroll

user whatever suits you best. if you use tbody a fixed height only tbody will scroll not the thead.

Biswajit Maji
  • 869
  • 13
  • 23