Fixed header row when rest of the table scrolls?

Discussion in 'CSS' started by akinak, Oct 10, 2008.

  1. #1
    I have a table with large data. I was able to create scrollbars with overflow:scroll; . But I want to keep header row of the table fixed while rest of the table scrolls. Is there any way to do this in CSS?

    Here is my code:
    <div id="box">
    <table width="100%" height="50%" border="1">
    <tr><th>Header 1<th>
    <th>Header 2</th></tr>
    <tr><td><a href="#" target="_blank">text</a></td>
    <td width="100">text</td></tr>
    <tr><td><a href="#" target="_blank">text</a></td>
    <td width="100">text</td></tr>
    </table></div>
    Code (markup):
    and CSS...
    #box{overflow:scroll;
    width:100%;
    height:10em;}
    Code (markup):
    plz help...
     
    akinak, Oct 10, 2008 IP
  2. buzzmaker

    buzzmaker Peon

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't think so!

    You could try creating another table for the headings which resides out of the <div id="box"> and remove the <th> from the table where you display the data inside <div>.

    Also, try overflow:auto;

    So that when you don't have much data, the scroolbars won't be visible.
     
    buzzmaker, Oct 15, 2008 IP