table锁定表头

本文介绍4种固定表头方式,效果如图:

方式一、使用两个table,.tHead作为表头,tBody包含表体;

<style type="text/css">
*{margin:0; padding:0;}
table{width:100%; table-layout:fixed; border-collapse: collapse;}
tr{height:30px;}
th{text-align:left; background:#F0F1F2; border-bottom:1px solid #CCCDD1;}
td{color:#666666; border-bottom:1px solid #CCCDD1;}
.tHead{position:fixed; left:0; top:0;}
.tBody{margin-top:30px;}
</style>
<table class="tHead">
    <tr>
        <th>title1</th>
        <th>title2</th>
        <th>title3</th>
        <th>title4</th>
        <th>title5</th>
    </tr>
</table>

<div class="tBody">
    <table>
        ......
    </table>
</div>

方式二:一个table

<table>
      <thead>
        <tr>
            <th>title1</th>
            <th>title2</th>
            <th>title3</th>
            <th>title4</th>
            <th>title5</th>
        </tr>
    </thead>
    <tbody>
        ......
    </tbody>
</table>
<style type="text/css">
*{margin:0; padding:0;}
table{border-collapse: collapse; width:100%; table-layout:fixed; margin:0 auto;}
tr{height:30px;}
th,td{border-bottom:1px solid #CCCDD1;}
thead{position:fixed; top:0px; display:table; width:100%; table-layout:fixed;}
thead tr th{background-color: #F0F1F2; border-top:1px solid #CCCDD1; text-align:left;}
tbody tr{display:table; width:100%; table-layout:fixed;}
tbody tr:first-child{margin-top:30px;}
</style>

方式三、一个table,只滚动tbody,滚动时copy一个表头显示在顶部

<style type="text/css">
*{margin:0; padding:0;}
table {border-collapse: collapse; width:100%; table-layout:fixed; margin:0 auto;}
table thead, table tbody tr {display:table; width:100%; table-layout:fixed;}
table thead{width:calc(100% - 1.5em);}
table tbody {display:block; height:300px; overflow-y:auto;}
tr{height:30px;}
th,td{border-bottom:1px solid #CCCDD1; text-align:center;}
</style>

方式四、一个table,使用jquery插件jquery.freezeheader.js

<style type="text/css">
*{margin:0; padding:0;}
table{border-collapse: collapse; width:100%; table-layout:fixed; margin:0 auto;}
tr{height:30px;}
th{background:#F0F1F2;}
th,td{border-bottom:1px solid #CCCDD1; text-align:center;}
</style>

调用:

在顶部浏览器中创建一个固定的头表:$("table").freezeHeader();

用固定高度创建一个固定的头表:$("table").freezeHeader({ ‘height‘: ‘300px‘ });

滚动时,固定表头相对顶部位置:$("table").freezeHeader({ ‘offset‘: ‘50px‘ });

时间: 2024-08-09 02:44:16

table锁定表头的相关文章

H5手机开发锁定表头和首列(惯性滚动)解决方案

前端时间移动端在做表格的时候需要这个功能,由于还有实现类似原生的惯性滚动功能,于是使用了iscroll插件. iscroll插件下载地址:iscroll5 该功能demo github地址: https://github.com/lyc152/front-special-effects/tree/master/table-fixed 下面看下代码结构: HTML: 1 <div class="data-table"> 2 <div class="t_l&qu

asp.net table表格表头及列固定实现

在开发中常会遇到table表格中列特别多,下拉后,表头就看不见了,水平滚动后,第1.2列就看不见了,于是需求就出来了,就是需要固定table的表头和列. demo结构如下图所示: demo下载地址:http://download.csdn.net/detail/taomanman/9124949 示例运行效果如下图所示: 版权声明:本文为博主原创文章,未经博主允许不得转载.

table表格表头类别分组效果

table表格表头类别分组效果:表格用来组织数据非常的便利,比如可以按照数据的类别进行或者其他方式有效的组织数据,有时候分类比较复杂,比如大的分类中还包括小的分类,下面就是一段类似的代码实例,希望能够对需要的朋友带来帮助.代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http

table固定表头滚动

table固定表头 使用scrollTop监听滚动   如下例 1.html <div class="tabflow" id="flowtable-cont"> <table> <thead><tr><th>年度</th><th>起降架次(万架)</th><th>旅客吞吐(万人)</th><th>货邮吞吐(万吨)</th>&

非常强大的table根据表头排序,点击表头名称,对其内容排序

js代码: 1 /** 2 * 通过表头对表列进行排序 3 * 4 * @param sTableID 5 * 要处理的表ID<table id=''> 6 * @param iCol 7 * 字段列id eg: 0 1 2 3 ... 8 * @param sDataType 9 * 该字段数据类型 int,float,date 缺省情况下当字符串处理 10 */ 11 function orderByName(sTableID, iCol, sDataType) { 12 var oTab

Saiku如何固定查询结果table的表头和首列

在使用saiku查询的时候,当“行”和“列”的维度内容过多时,在查看时只看到数据,不知道是什么数据,维度不清楚,得来回拖动滚动条才行,所以同事提出想要固定“表头”和“首列”. 在网上找了一些现成的插件使用后效果都不理想,所以决定自己动手,丰衣足食. 我的思路来自:http://www.cnblogs.com/sorex/archive/2011/06/30/2093499.html 使用四个table,其中一个为saiku原有的,再增加3个,思路效果图: js代码实现: 1.找到SaikuTab

固定table的表头CSS&amp;JQuery

対応ブラウザのバージョン Internet Explorer 9 / 10 / 11 Firefox 29 Google Chrome 34 Safari 5 Opera 12 表头固定的方法 <table class="table-design tablelock1"> <thead> <tr> <th>TableHeader1</th><th>TableHeader2</th> <th>

固定table的表头同时固定列

table表格是我们最常使用的数据显示一种形式,但有时候数据比较多的时候 就需要我们去固定表头,固定列.我这里用简单的css样式配合两句js脚本来实现,希望能够去帮到你. <div class="tableContainer"> <div class="sideTable"> <span>产品小类</span> <div id="sideTable"> <table> <

table锁定列的一个方法.及琢磨思路

         div {              width: 600px;              overflow-x:scroll;               margin-left:5em;              border:1px solid red;         }         .headcol {             position:absolute;              width:5em;              background-co