用CSS实现的固定表头的HTML表格
点击次数:23 次 发布日期:2008-11-26 21:11:13 作者:源代码网
|
源代码网推荐原地址见: http://www.imaputz.com/cssStuff/bulletVersion.html。 源代码网推荐 源代码网推荐<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> 源代码网推荐<style type="text/css"> 源代码网推荐<!-- 源代码网推荐body { 源代码网推荐 background: #FFF; 源代码网推荐 color: #000; 源代码网推荐 font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif; 源代码网推荐 margin: 10px; 源代码网推荐 padding: 0 源代码网推荐} 源代码网推荐 源代码网推荐table, td, a { 源代码网推荐 color: #000; 源代码网推荐 font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif 源代码网推荐} 源代码网推荐 源代码网推荐.td 源代码网推荐 { 源代码网推荐 nowrap:""true""; 源代码网推荐 } 源代码网推荐 源代码网推荐div.tableContainer { 源代码网推荐 clear: both; 源代码网推荐 border: 1px solid #963; 源代码网推荐 height: 285px; 源代码网推荐 overflow: auto; 源代码网推荐 width: 100%; 源代码网推荐} 源代码网推荐 源代码网推荐/* WinIE 6.x needs to re-account for it""s scrollbar. Give it some padding */ 源代码网推荐html div.tableContainer/* */ { 源代码网推荐 padding: 0 16px 0 0 源代码网推荐} 源代码网推荐 源代码网推荐/* clean up for allowing display Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐html>body div.tableContainer { 源代码网推荐 height: auto; 源代码网推荐 padding: 0; 源代码网推荐 width: 740px 源代码网推荐} 源代码网推荐 源代码网推荐/* Reset overflow value to hidden for all non-IE browsers. */ 源代码网推荐/* Filter out Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐head:first-child+body div[class].tableContainer { 源代码网推荐 height: 285px; 源代码网推荐 overflow: hidden; 源代码网推荐 width: 756px 源代码网推荐} 源代码网推荐 源代码网推荐/* define width of table. IE browsers only */ 源代码网推荐/* if width is set to 100%, you can remove the width */ 源代码网推荐/* property from div.tableContainer and have the div scale */ 源代码网推荐div.tableContainer table { 源代码网推荐 float: left; 源代码网推荐 width: 100% 源代码网推荐} 源代码网推荐 源代码网推荐/* WinIE 6.x needs to re-account for padding. Give it a negative margin */ 源代码网推荐html div.tableContainer table/* */ { 源代码网推荐 margin: 0 -16px 0 0 源代码网推荐} 源代码网推荐 源代码网推荐/* define width of table. Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐html>body div.tableContainer table { 源代码网推荐 float: none; 源代码网推荐 margin: 0; 源代码网推荐 width: 740px 源代码网推荐} 源代码网推荐 源代码网推荐/* define width of table. Add 16px to width for scrollbar. */ 源代码网推荐/* All other non-IE browsers. Filter out Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐head:first-child+body div[class].tableContainer table { 源代码网推荐 width: 756px 源代码网推荐} 源代码网推荐 源代码网推荐/* set table header to a fixed position. WinIE 6.x only */ 源代码网推荐/* In WinIE 6.x, any element with a position property set to relative and is a child of */ 源代码网推荐/* an element that has an overflow property set, the relative value translates into fixed. */ 源代码网推荐/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */ 源代码网推荐thead.fixedHeader tr { 源代码网推荐 position: relative; 源代码网推荐 /* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */ 源代码网推荐 top: expression(document.getElementById("tableContainer").scrollTop) 源代码网推荐} 源代码网推荐 源代码网推荐 源代码网推荐/* set THEAD element to have block level attributes. All other non-IE browsers */ 源代码网推荐/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */ 源代码网推荐/* Filter out Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐head:first-child+body thead[class].fixedHeader tr { 源代码网推荐 display: block 源代码网推荐} 源代码网推荐 源代码网推荐/* make the TH elements pretty */ 源代码网推荐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 源代码网推荐} 源代码网推荐 源代码网推荐/* make the A elements pretty. makes for nice clickable headers */ 源代码网推荐thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited { 源代码网推荐 color: #FFF; 源代码网推荐 display: block; 源代码网推荐 text-decoration: none; 源代码网推荐 width: 100% 源代码网推荐} 源代码网推荐 源代码网推荐/* make the A elements pretty. makes for nice clickable headers */ 源代码网推荐/* WARNING: swapping the background on hover may cause problems in WinIE 6.x */ 源代码网推荐thead.fixedHeader a:hover { 源代码网推荐 color: #FFF; 源代码网推荐 display: block; 源代码网推荐 text-decoration: underline; 源代码网推荐 width: 100% 源代码网推荐} 源代码网推荐 源代码网推荐/* define the table content to be scrollable */ 源代码网推荐/* set TBODY element to have block level attributes. All other non-IE browsers */ 源代码网推荐/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */ 源代码网推荐/* induced side effect is that child TDs no longer accept width: auto */ 源代码网推荐/* Filter out Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐head:first-child+body tbody[class].scrollContent { 源代码网推荐 display: block; 源代码网推荐 height: 262px; 源代码网推荐 overflow: auto; 源代码网推荐 width: 100% 源代码网推荐} 源代码网推荐 源代码网推荐/* make TD elements pretty. Provide alternating classes for striping the table */ 源代码网推荐/* http://www.alistapart.com/articles/zebratables/ */ 源代码网推荐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 源代码网推荐} 源代码网推荐 源代码网推荐tbody.scrollContent tr.alternateRow td { 源代码网推荐 background: #EEE; 源代码网推荐 border-bottom: 1px solid #EEE; 源代码网推荐 border-left: 1px solid #EEE; 源代码网推荐 border-right: 1px solid #AAA; 源代码网推荐 border-top: 1px solid #AAA; 源代码网推荐 padding: 2px 3px 源代码网推荐} 源代码网推荐 源代码网推荐/* define width of TH elements: 1st, 2nd, and 3rd respectively. */ 源代码网推荐/* All other non-IE browsers. Filter out Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐/* Add 16px to last TH for scrollbar padding */ 源代码网推荐/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors */ 源代码网推荐head:first-child+body thead[class].fixedHeader th { 源代码网推荐 width: 200px 源代码网推荐} 源代码网推荐 源代码网推荐head:first-child+body thead[class].fixedHeader th + th { 源代码网推荐 width: 250px 源代码网推荐} 源代码网推荐 源代码网推荐head:first-child+body thead[class].fixedHeader th + th + th { 源代码网推荐 border-right: none; 源代码网推荐 padding: 4px 4px 4px 3px; 源代码网推荐 width: 316px 源代码网推荐} 源代码网推荐 源代码网推荐/* define width of TH elements: 1st, 2nd, and 3rd respectively. */ 源代码网推荐/* All other non-IE browsers. Filter out Opera 5.x/6.x and MacIE 5.x */ 源代码网推荐/* Add 16px to last TH for scrollbar padding */ 源代码网推荐/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors */ 源代码网推荐head:first-child+body tbody[class].scrollContent td { 源代码网推荐 width: 200px 源代码网推荐} 源代码网推荐 源代码网推荐head:first-child+body tbody[class].scrollContent td + td { 源代码网推荐 width: 250px 源代码网推荐} 源代码网推荐 源代码网推荐head:first-child+body tbody[class].scrollContent td + td + td { 源代码网推荐 border-right: none; 源代码网推荐 padding: 2px 4px 2px 3px; 源代码网推荐 width: 300px 源代码网推荐 源代码网推荐/* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */ 源代码网推荐top: expression(document.getElementById("tableContainer").scrollTop) 源代码网推荐} 源代码网推荐--> 源代码网推荐</style> 源代码网推荐</head><body> 源代码网推荐<div id="tableContainer" class="tableContainer"> 源代码网推荐<table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable"> 源代码网推荐<thead class="fixedHeader"> 源代码网推荐 <tr> 源代码网推荐 <th><a href="#">Header 1</a></th> 源代码网推荐 <th><a href="#">Header 2</a></th> 源代码网推荐 <th><a href="#">Header 3</a></th> 源代码网推荐 <th><a href="#">Header 4</a></th> 源代码网推荐 <th><a href="#">Header 5</a></th> 源代码网推荐 <th><a href="#">Header 6</a></th> 源代码网推荐 <th><a href="#">Header 7</a></th> 源代码网推荐 </tr> 源代码网推荐</thead> 源代码网推荐<tbody class="scrollContent"> 源代码网推荐 <tr> 源代码网推荐 <td>Cell Content 1</td> 源代码网推荐 <td>Cell Content 2</td> 源代码网推荐 <td>Cell Content 3</td> 源代码网推荐 <td>Cell Content 4</td> 源代码网推荐 <td>Cell Content 5</td> 源代码网推荐 <td>Cell Content 6</td> 源代码网推荐 <td>Cell Content 7</td> 源代码网推荐 </tr> 源代码网推荐 <tr> 源代码网推荐 <td>More Cell Content 1</td> 源代码网推荐 <td>More Cell Content 2</td> 源代码网推荐 <td>More Cell Content 3</td> 源代码网推荐 <td>More Cell Content 4</td> 源代码网推荐 <td>More Cell Content 5</td> 源代码网推荐 <td>More Cell Content 6</td> 源代码网推荐 <td>More Cell Content 7</td> 源代码网推荐 </tr> 源代码网推荐 <tr> 源代码网推荐 <td nowrap>Even More Cell Content 1</td> 源代码网推荐 <td nowrap>Even More Cell Content 2</td> 源代码网推荐 <td nowrap>Even More Cell Content 3</td> 源代码网推荐 <td nowrap>Even More Cell Content 4</td> 源代码网推荐 <td nowrap>Even More Cell Content 5</td> 源代码网推荐 <td nowrap>Even More Cell Content 6</td> 源代码网推荐 <td nowrap>Even More Cell Content 7</td> 源代码网推荐 </tr> 源代码网推荐 <tr> 源代码网推荐 <td>And Repeat 1</td> 源代码网推荐 <td>And Repeat 2</td> 源代码网推荐 <td>And Repeat 3</td> 源代码网推荐 <td>And Repeat 4</td> 源代码网推荐 <td>And Repeat 5</td> 源代码网推荐 <td>And Repeat 6</td> 源代码网推荐 <td>And Repeat 7</td> 源代码网推荐 </tr> 源代码网推荐</tbody> 源代码网推荐</table> 源代码网推荐</div> 源代码网推荐 源代码网推荐</body></html> 源代码网推荐 源代码网推荐 源代码网推荐 源代码网供稿. |
