table 表头永远置顶

    以下仅供参考!不对的评论下指正!  

 

 

    table貌似无论怎么设置td 高度table都会根据数据的变化而变化(宽度table-layout:fixed样式可以做到固定)高度而且当数据少的时候高度会平分table高度导致页面不好看whenload方法是用来解决当数据少的时候设置table高度使得界面不会难看!

   

   

     现在table头不动的解决方式是使用2个table  一个用来显示我们需要看到的表头table1 一个用来显示表体table2,他们用用同样的宽度    表体装载在一个稍大于表体宽度的div2下(宽度自己看着设置) 表头table1和div1装载在相同的父标签div下  

   为了使得table1和table2显示宽度上能平齐用空白占位符占用了table2对应th区域。对应的th用占用相等空间的占位符占用。

 

      以下有空格占位符的案例(都是百度的)

  == 普通的英文半角空格

  ==   ==   == no-break space (普通的英文半角空格但不换行)

  == 中文全角空格 (一个中文宽度)

  ==   == en空格 (半个中文宽度)

  ==   == em空格 (一个中文宽度)

  == 四分之一em空格 (四分之一中文宽度)

 

相比平时的空格( ),nbsp拥有不间断(non-breaking)特性。即连续的nbsp会在同一行内显示。即使有100个连续的nbsp,浏览器也不会把它们拆成两行。 

 

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
.rendDivices,.CheckHis {
	border: 1px solid #C1C1C1;
}
th {
	height: 10px;
}
td {
    word-wrap:break-word;
    width: 11%;
	text-align: left;
	height: 10px;
}
tr{

max-height:10px;
}

</style>
<script  type="text/javascript">
function whenLoad(){
var table = document.getElementById("checkShowTable");
var cel=table.children[0].children;
if(cel.length<20){
table.style.height=cel.length*20+"px";
var sss=0;
}
}
</script>
<title>test</title>
</head>
<body οnlοad="whenLoad()">
<div >
		<div style="margin: auto; boder: 3px solid red; width: 800px;height:600px;">
			<table id="checkShowTableHead" class="rendDivices"
				style="margin-top: 10px;width:100%;table-layout:fixed">
				<tr>
					<th class="rendDivices thnc">请问</th>
					<th class="rendDivices thnc">去问人体有</th>
					<th class="rendDivices thnc">去问人体</th>
					<th class="rendDivices thnc">阿斯蒂芬</th>
					<th class="rendDivices thnc">自行车v不</th>
					<th class="rendDivices thnc">人推哦地方</th>
					<th class="rendDivices thnc">阿斯蒂芬</th>
				</tr>
			</table>
			
			<div style="width:815px;height: 100%;overflow:auto;margin-top:0;"}>
			<table id="checkShowTable" class="rendDivices"
				style="width:800px;height: 100%;margin-top:0;margin-top: 0;table-layout:fixed">
					<tr>
					<th class="rendDivices thncr">&#12288;&#12288;</th>
					<th class="rendDivices thncr">&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;</th>
					<th class="rendDivices thncr">&#12288;&#12288;&#12288;&#12288;</th>
					<th class="rendDivices thncr">&#12288;&#12288;&#12288;&#12288;</th>
					<th class="rendDivices thncr">&#12288;&#12288;&#12288;&#12288;&#12288;</th>
					<th class="rendDivices thncr">&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;</th>
					<th class="rendDivices thncr">&#12288;&#12288;&#12288;&#12288;</th>
				</tr>
					<tr>
					<td class="rendDivices thncr">1111111111111111</td>
					<td class="rendDivices thncr">2222222222</td>
					<td class="rendDivices thncr">33333333333333333333333333333333</td>
					<td class="rendDivices thncr">555555555555555555555555555555555555</td>
					<td class="rendDivices thncr">44444444444444444444444444444444444444444444444444444444444</td>
					<td class="rendDivices thncr">66666666666666666666666666666666666666666666666</td>
					<td class="rendDivices thncr">77777777777777777777777777777777777777</td>
				</tr>
			</table>
		
		</div>
		</div>
	</div>
</body>
</html>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值