---
title: "固定table表头"
author: "daidalei321"
date: "2011-07-05T16:18:39Z"
tags: []
categories: ["Web前端"]
slug: "table"
draft: false
lastmod: "2011-07-05T16:18:39Z"
id: 1115059
url: "https://daidalei321.iteye.com/blog/1115059"
---

&lt;html&gt;  
&lt;head&gt;  
&lt;style type="text/css" mce\_bogus="1"&gt;

div.tableContainer {  
 clear: both;  
 border: 1px solid #963;  
 height: expression(document.body.clientHeight\*0.3);  
 overflow: auto;  
 width: 100%;  
}

div.tableContainer table {  
 float: left;  
 width: 100%  
}

thead.fixedHeader tr {  
 position: relative;

 top: expression(document.getElementById("tableContainer").scrollTop)  
}

thead.fixedHeader th {  
 background: #C96;  
 border-left: 1px solid #EB8;  
 border-right: 1px solid #B74;  
 border-top: 1px solid #EB8;  
 font-weight: normal;  
 padding: 4px 3px;  
 text-align: center  
}

tbody.scrollContent td, tbody.scrollContent tr.normalRow td {  
 background: #FFF;  
 border-bottom: 1px solid #EEE;  
 border-left: 1px solid #EEE;  
 border-right: 1px solid #AAA;  
 border-top: 1px solid #AAA;  
 padding: 2px 3px  
}

&lt;/style&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;div id="tableContainer" class="tableContainer"&gt;  
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%"&gt;  
&lt;thead class="fixedHeader"&gt;  
 &lt;tr&gt;  
  &lt;th&gt;表头 1&lt;/th&gt;  
  &lt;th&gt;表头 2&lt;/th&gt;  
  &lt;th&gt;表头 3&lt;/th&gt;  
  &lt;th&gt;表头 4&lt;/th&gt;  
  &lt;th&gt;表头 5&lt;/th&gt;  
  &lt;th&gt;表头 6&lt;/th&gt;  
  &lt;th&gt;表头 7&lt;/th&gt;  
 &lt;/tr&gt;  
&lt;/thead&gt;  
&lt;tbody class="scrollContent"&gt;  
 &lt;tr&gt;  
  &lt;td&gt;Cell Content 1&lt;/td&gt;  
  &lt;td&gt;Cell Content 2&lt;/td&gt;  
  &lt;td&gt;Cell Content 3&lt;/td&gt;  
  &lt;td&gt;Cell Content 4&lt;/td&gt;  
  &lt;td&gt;Cell Content 5&lt;/td&gt;  
  &lt;td&gt;Cell Content 6&lt;/td&gt;  
  &lt;td&gt;Cell Content 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td&gt;More Cell Content 1&lt;/td&gt;  
  &lt;td&gt;More Cell Content 2&lt;/td&gt;  
  &lt;td&gt;More Cell Content 3&lt;/td&gt;  
  &lt;td&gt;More Cell Content 4&lt;/td&gt;  
  &lt;td&gt;More Cell Content 5&lt;/td&gt;  
  &lt;td&gt;More Cell Content 6&lt;/td&gt;  
  &lt;td&gt;More Cell Content 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td&gt;Even More Cell Content 1&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 2&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 3&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 4&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 5&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 6&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td&gt;And Repeat 1&lt;/td&gt;  
  &lt;td&gt;And Repeat 2&lt;/td&gt;  
  &lt;td&gt;And Repeat 3&lt;/td&gt;  
  &lt;td&gt;And Repeat 4&lt;/td&gt;  
  &lt;td&gt;And Repeat 5&lt;/td&gt;  
  &lt;td&gt;And Repeat 6&lt;/td&gt;  
  &lt;td&gt;And Repeat 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td&gt;Even More Cell Content 1&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 2&lt;/td&gt;  
  &lt;td&gt;ven More Cell Content 3&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 4&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 5&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 6&lt;/td&gt;  
  &lt;td&gt;Even More Cell Content 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td&gt;And Repeat 1&lt;/td&gt;  
  &lt;td&gt;And Repeat 2&lt;/td&gt;  
  &lt;td&gt;And Repeat 3&lt;/td&gt;  
  &lt;td&gt;And Repeat 4&lt;/td&gt;  
  &lt;td&gt;And Repeat 5&lt;/td&gt;  
  &lt;td&gt;And Repeat 6&lt;/td&gt;  
  &lt;td&gt;And Repeat 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td nowrap&gt;Even More Cell Content 1&lt;/td&gt;  
  &lt;td nowrap&gt;Even More Cell Content 2&lt;/td&gt;  
  &lt;td nowrap&gt;Even More Cell Content 3&lt;/td&gt;  
  &lt;td nowrap&gt;Even More Cell Content 4&lt;/td&gt;  
  &lt;td nowrap&gt;Even More Cell Content 5&lt;/td&gt;  
  &lt;td nowrap&gt;Even More Cell Content 6&lt;/td&gt;  
  &lt;td nowrap&gt;Even More Cell Content 7&lt;/td&gt;  
 &lt;/tr&gt;  
 &lt;tr&gt;  
  &lt;td&gt;And Repeat 1&lt;/td&gt;  
  &lt;td&gt;And Repeat 2&lt;/td&gt;  
  &lt;td&gt;And Repeat 3&lt;/td&gt;  
  &lt;td&gt;And Repeat 4&lt;/td&gt;  
  &lt;td&gt;And Repeat 5&lt;/td&gt;  
  &lt;td&gt;And Repeat 6&lt;/td&gt;  
  &lt;td&gt;And Repeat 7&lt;/td&gt;  
 &lt;/tr&gt;  
&lt;/tbody&gt;  
&lt;/table&gt;  
&lt;/div&gt;  
&lt;/body&gt;

&lt;/html&gt;