固定table的thead,tbody可滾動

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<style>		   
			table tbody {  
				display:block;  
				height:500px;  
				overflow-y:scroll;  
			}  
			
			td, th{border:solid red 1px;}			  
			  
			table thead, tbody tr {  
				display:table;  
				width:100%;  
				table-layout:fixed;  
			}  			  
			  
			table thead {  
				/*Standard */
				width: calc( 100% - 8px );
				/*chrome safari*/
				width: -webkit-calc( 100% - 8px );
				/*Firefox*/
				width: -moz-calc( 100% - 8px );				
			}
		</style>
	</head>
	<body>
		<table>   
			<thead>  
				<tr><th>aaa</th><th>bbb</th><th>aaa</th><th>bbb</th><th>aaa</th><th>bbb</th></tr>  
			</thead> 
			<tbody>  
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
				<tr><td>1</td><td>AAAAAAA</td><td>2</td><td>BBBBBBB</td><td>3</td><td>CCCCCC</td></tr>
			</tbody>  
		</table>  
	</body>
</html>
相關文章
相關標籤/搜索