html和js相关

1,table 固定表头的方法
方法一:

	.table-container {
  width: 100%;
  height: 100%;
  overflow: auto;
}
/* 首列固定 */
.table-container thead tr > th:first-child,
.table-container tbody tr > td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}
/* 表头固定 */
.table-container thead tr > th {
  position: sticky;
  top: 0;
  z-index: 2;
} 
/* 表头首列强制最顶层 */
.table-container thead tr > th:first-child {
  z-index: 3;
}

方法二:

table tbody {
	display: block;
	height: 450px;
	overflow-y: scroll;
} 
table thead, tbody tr {
	display: table;
	width: 100%;
	table-layout: fixed;
} 
table thead {
	width: calc(100% - 1em)
}

方法三:

<html>
<head>
    <title>表頭固定</title>
</head>
<style>
        .table-head{padding-right:17px;background-color:#999;color:#000;}
        .table-body{width:100%;height: 80px;overflow-y: scroll;}
        .table-head table,.table-body table{width:100%}
        .table-body table tr:nth-child(2n+1){background-color: #f2f2f2;}
</style>
<body>
    <div style="width:100%;" id="aa">
        <div class="table-head">
            <table>
                <thead>
                    <tr>
                        <th colspan="2">序號</th>
                        <th colspan="2">內容</th>
                    </tr>
                    <tr>
                        <th id="h_1">序號1</th>
                        <th>序號2</th>
                        <th>內容1</th>
                        <th>內容2</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="table-body">
            <table>
                <tbody>
                    <tr><td id ="b_1">ceshi</td><td>ceshi</td><td>ceshi</td><td>ceshi</td></tr>
                    <tr><td>1</td><td>2</td><td>ceshi1</td><td>ceshi2</td></tr>
                    <tr><td>1</td><td>2</td><td>ceshi1</td><td>ceshi2</td></tr>
                    <tr><td>1</td><td>2</td><td>ceshi1</td><td>ceshi2</td></tr>
                    <tr><td>1</td><td>2</td><td>ceshi1</td><td>ceshi2</td></tr>              
                </tbody>
            </table>
        </div>
    </div>
</body>
<script>
  var head_list=["h1","h2"];
  var dictable={h1:"b1", h2"b2"};
  for (i=0;i<head_list.length;i++){
	var sub_x=document.getElementById(dictable[head_list[i]]);
	var wid_y=getComputedStyle(sub_x).width;
	document.getElementById(head_list[i]).style=parseInt(wid_y) + 10 + "px";
}
clickshow=function(id){
	var x = document.getElementById(id);
	var class_a = x.getAttribute("class");
	x.setAttribute("class","new_style_class");
}
</script>
</html>

js脚本可以调整宽度对齐

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值