固定table的thead,tbody可滚动

本文介绍了一种使用HTML和CSS实现的具有固定表头和垂直滚动功能的表格样式。通过将表格主体设置为可滚动,同时保持表头固定,使得在查看长表格数据时更加方便。文章提供了具体的HTML结构和CSS样式代码。
摘要由CSDN通过智能技术生成
<!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>

 

转载于:https://my.oschina.net/u/266034/blog/896651

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值