Keep table headers still when scrolling a table - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Table Scroll

Description

Keep table headers still when scrolling a table

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
.tblSearchMedia1<!-- ww  w .j a  v  a 2s.c o m-->
 {
   width:501px;
}

.tblSearchMedia1 tbody {
   height:51px;
   overflow:auto;
   display:block;
   width:100%;
}

.tblSearchMedia1 td {
   padding:4px 11px;
}

.tblSearchMedia1 thead th, .tblSearchMedia1 tbody td
 {
   width:100px;
}

.tblSearchMedia1 thead>tr {
   position:relative;
   display:block;
}
</style> 
 </head> 
 <body> 
  <table class="tblSearchMedia1"> 
   <thead> 
    <tr> 
     <th>Lorem </th> 
     <th>Lorem ips</th> 
     <th>Lorem i</th> 
     <th>Lorem ipsu</th> 
     <th>Lorem ipsu</th> 
    </tr> 
   </thead> 
   <tbody data-bind="foreach: MediaGroups"> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
    <tr> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text:ID">L</td> 
     <td data-bind="text: ID">L</td> 
     <td data-bind="text: ID">L</td> 
    </tr> 
   </tbody> 
  </table>  
 </body>
</html>

Related Tutorials