My pen:
http://codepen.io/helloworld/pen/qHDFB
I would like to create a html table:
I want to use CSS only.
It should work in IE10+ and latest FF/Chrome.
You can also use the new CSS Grid Layout from Microsoft which will be ported over to webkit etc... with -ms-grid etc...
How can I make the above individual sample work that the header stays fixed and and the body of the table has vertical scrollbars not the html body itself?
HTML
<table>
<thead>
<tr>
<th>
<div>First</div>
</th>
<th>
<div>Second</div>
</th>
<th>
<div>Third</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
</tbody>
</table>
CSS
body, html{
margin:0;
padding:0;
height:100%;
width:100%;
}
table{
width:100%;
height:100%;
}
td{
width:33%;
border:black solid 1px;
}
tbody{
overflow-x:hidden;
overflow-y:auto;
}
tr td{
text-align:center;
height:100px;
}
th{
background:lightgray;
padding:10px;
border:black solid 1px;
}
Create a Table That Has a Fixed Header. We can create an HTML table that has a fixed header with some CSS. We set the height of the table element to 120px to make restrict the height of it so we can make it scrollable. To make it scrollable, we set the overflow CSS property to scroll .
By setting the position property to “sticky” and specifying “0” as a value of the top property for the <th> element.
Isn't this what you're looking for? - http://www.imaputz.com/cssStuff/bigFourVersion.html
Just view the source of the example, and this should get you going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With