I want to make header of my table fixed. Table is present inside the scrollable div. Below is my code.
<div id="table-wrapper"> <div id="table-scroll"> <table bgcolor="white" border="0" cellpadding="0" cellspacing="0" id="header-fixed" width="100%" overflow="scroll" class="scrollTable"> <thead> <tr> <th>Order ID</th> <th>Order Date</th> <th>Status</th> <th>Vol Number</th> <th>Bonus Paid</th> <th>Reason for no Bonus</th> </tr> </thead> <tbody> <tr> <td><%=snd.getOrderId()%></td> <td><%=snd.getDateCaptured()%></td> <td><%=snd.getOrderStatus()%></td> <td>Data Not Available</td> <td>Data Not Available</td> <td>Data Not Available</td> </tr> </tbody> </table> </div> </div> Below is my CSS, which I am using for the above div:
#table-wrapper { position:relative; } #table-scroll { height:250px; overflow:auto; margin-top:20px; } #table-wrapper table { width:100%; } #table-wrapper table * { background:white; color:black; } #table-wrapper table thead th .text { position:absolute; top:-20px; z-index:2; height:20px; width:35%; border:1px solid red; } 