table标题栏固定左右可滚动

http://jsrun.net/2iiKp/edit 

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
				body {
		  text-align:center;
		  font-family:微软雅黑;
		}

		.fixedTable > thead > tr > th, .fixedTable > tbody > tr > td {
		  width: 3%!important;
		}

		#fixedTab,#grid {
		  width: 1300px;
		  border: 1px solid gray;
		}
		td,th{
		  height:35px;
		  text-align:center;
		}
		
		#contenter {
		  position: relative;
		  width: 800px;
		  height:400px;
		  margin: auto;
		  background-color: white;
		  border: 1px solid black;
		  position:relative;
		}

		#fixedDiv {
		  position: absolute;
		  left: 0;
		  overflow: hidden;
		}

		#fixedTab th {
		  background-color: #4ca9f7;
		  color: white;
		}

		#mainDiv{
		  height:465px;
		  width: 1300px;
		  overflow:auto;
		  overflow-x:hidden;
		}
	</style>
</head>
<body>
	<h2>缺点:右边的滚动条不能固定</h2>
<h3>查看源码:<a href="http://jsrun.net/2iiKp/edit">http://jsrun.net/2iiKp/edit</a></h3>

<div id="contenter" style="overflow-x:auto;height:400px;">
  <div id="fixedDiv">
  <table id="fixedTab" class="fixedTable" border="1" cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <th>姓名</th>
      <th>性别</th>
      <th>爱好</th>
      <th>学历</th>
      <th>特长</th>
      <th>性格</th>
      <th>数学</th>
      <th>语文</th>
      <th>英语</th>
      <th>体育</th>
      <th>美术</th>
      <th>音乐</th>
      <th>早操</th>
      <th>地理</th>
    </tr>
  </thead>
  </table>
</div>
  <div id="mainDiv">
  <table id="grid" style="margin-top:35px;" class="fixedTable" border="1" cellpadding="0" cellspacing="0">
<!--   <thead style="display:none;">
    <tr>
      <th>姓名</th>
      <th>性别</th>
      <th>爱好</th>
      <th>学历</th>
      <th>特长</th>
      <th>性格</th>
      <th>数学</th>
      <th>语文</th>
      <th>英语</th>
      <th>体育</th>
      <th>美术</th>
      <th>音乐</th>
      <th>早操</th>
      <th>地理</th>
    </tr>
  </thead> -->
    <tbody>
      <tr>
        <td>1</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
      <tr>
        <td>sa</td>
        <td>sf</td>
        <td>sg</td>
        <td>dd</td>
        <td>zc</td>
        <td>zc</td>
        <td>vc</td>
        <td>vb</td>
        <td>fg</td>
        <td>cn</td>
        <td>sf</td>
        <td>zx</td>
        <td>cb</td>
        <td>ub</td>
      </tr>
    </tbody>
  </table>
</div>
</div>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值