I want to do this as easily as possible with out any additional libraries.
In my very long table I want to add a scrollbar to the If you don't want to wrap a table under any div: you can wrap the content of the html css see my jsfiddle, forked from yours: http://jsfiddle.net/VTNax/2/ These solutions often have issues with the header columns aligning with the body columns, and may not work properly when resizing. I know you didn't want to use an additional library, but if you happen to be using jQuery, this one is really small. It supports fixed header, footer, column spanning (colspan), horizontal scrolling, resizing, and an optional number of rows to display before scrolling starts. jQuery.scrollTableBody (GitHub) As long as you have a table with proper This is because you are adding your So for that you have to make a make another Now your header is fixed and the body will scroll. And the header will remain there. tag so
table{
table-layout: fixed;
}
tbody{
display: block;
overflow: auto;
}
<tbody>
in a scrollable <div>
:....
<tbody>
<tr>
<td colspan="2">
<div class="scrollit">
<table>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
...
.scrollit {
overflow:scroll;
height:100px;
}
<thead>
, <tbody>
, and (optional) <tfoot>
, all you need to do is this:$('table').scrollTableBody();
<tbody>
tag before <td>
in table you cannot print any data without <td>
.<div>
say #header
with position: fixed;
header
{
position: fixed;
}
<div>
which will act as <tbody>
tbody
{
overflow:scroll;
}