1.html

<div class="custom-fold-table">
<table cellpadding="0" cellspacing="0" width="100%" class="ellipsis-thead custom-table last-column-center table-border">
<thead>
<tr>
<th width="12%">编号</th>
<th width="18%" class="tal">名称</th>
<th width="12%" class="tal">总造价(元)</th>
<th width="12%" class="tal">占工程费用比例</th>
<th width="12%" class="tal">单方造价(元/m2)</th>
<th width="9%">指标标杆</th>
</tr>
</thead>
</table>
<div class="tree-table">
<div class="tr-level-1">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>001</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%"><p class="red">154561</p></td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-2">
<div class="tr-level-2">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click font-bold"><div class="arrow-icon"></div>0011</td>
<td width="18%" class="font-bold">土建工程</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%"><span class="red">154561</span></td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-3">
<div class="tr-level-3">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>00111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-4">
<div class="tr-level-4">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-5">
<div class="tr-level-5">
<table class="custom-table ellipsis-table last-column-center table-border">

<tbody>
<tr>
<td width="12%">001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="tr-level-3">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>00111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-4">
<div class="tr-level-4">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-5">
<div class="tr-level-5">
<table class="custom-table ellipsis-table last-column-center table-border">

<tbody>
<tr>
<td width="12%">001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tr-level-2">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click font-bold"><div class="arrow-icon"></div>0011</td>
<td width="18%" class="font-bold">土建工程</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%"><span class="red">154561</span></td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-3">
<div class="tr-level-3">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>00111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-4">
<div class="tr-level-4">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-5">
<div class="tr-level-5">
<table class="custom-table ellipsis-table last-column-center table-border">

<tbody>
<tr>
<td width="12%">001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="tr-level-3">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>00111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-4">
<div class="tr-level-4">
<table class="custom-table ellipsis-table last-column-center table-border">
<tbody>
<tr>
<td width="12%" class="fold-click"><div class="arrow-icon"></div>001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
<div class="level-5">
<div class="tr-level-5">
<table class="custom-table ellipsis-table last-column-center table-border">

<tbody>
<tr>
<td width="12%">001111</td>
<td width="18%">分部分项合计</td>
<td width="12%">154323000</td>
<td width="12%">20%</td>
<td width="12%">154561</td>
<td width="9%">154323000</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div>
</div>
2.css

/*折叠表格*/
.custom-fold-table .custom-table{width:100%;border-collapse:collapse;}
.custom-fold-table .custom-table>thead>tr{background-color:#fffbf8;}
.custom-fold-table .custom-table>thead>tr>th{position:relative;height:44px;font-size:14px;text-align:left;padding:0 10px;}
.custom-fold-table .custom-table>thead>tr>th:first-child{border-left:0;}
.custom-fold-table .custom-table.first-column-center>thead>tr>th:first-child,
.custom-fold-table .custom-table.first-column-center>tbody>tr>td:first-child{text-align:center;}
.custom-fold-table .custom-table.last-column-center>thead>tr>th:last-child,.custom-fold-table .custom-table.last-column-center>tbody>tr>td:last-child{text-align:center;}
.custom-fold-table .custom-table>tbody>tr:hover{background-color:#FEF3F3;}
.custom-fold-table .custom-table>tbody>tr>td{position:relative;text-align:left;padding:0 10px;color:#354052; border-bottom:1px solid #e5e5e5;height: 40px;}
.ellipsis-thead{table-layout:fixed;}
.ellipsis-thead th{width:100%;}
/*表格有边框*/
.custom-fold-table .table-border th{padding: 0 3px; border:1px solid #e5e5e5; border-right: none;}
.custom-fold-table .table-border>thead>tr>th:first-child{border-left:1px solid #e5e5e5;;}
.custom-fold-table .table-border td{border-left:1px solid #e5e5e5;}
.custom-fold-table .table-border{border-right:1px solid #e5e5e5; }
.tree-table .tr-level-2:last-of-type div:last-of-type:before{content:'';border-bottom:0;}
/*树形表格组件*/
/*.tree-table table>tbody>tr:hover{background-color:transparent;}*/
.tree-table .tr-level-1{position:relative;/*background-color:#fff;*/}
.tree-table .tr-level-2{position:relative;display:none;/*background-color:#f4f8fb;*/}
.tree-table .tr-level-2 table>tbody>tr>td:first-child{text-indent:35px;position:relative;}
.tree-table .tr-level-2:before{content:'';position:absolute;left:0;top:0;bottom:0;width:50px;border-top:1px solid #f2f2f2;border-bottom:1px solid #f2f2f2;}
.tree-table .tr-level-3{position:relative;display:none;/*background-color:#E9EFF5;*/}
.tree-table .tr-level-3 table>tbody>tr>td:first-child{text-indent:58px;}
.tree-table .tr-level-3:before{content:'';position:absolute;left:0;top:-1px;bottom:0;width:70px;border-top:2px solid #f2f2f2;border-bottom:2px solid #f2f2f2;}
.tree-table .tr-level-4,.tree-table .tr-level-5{position:relative;display:none;/*background-color:#e3eaf0;*/}
.tree-table .tr-level-4 table>tbody>tr>td:first-child{text-indent:80px;}
.tree-table .tr-level-5 table>tbody>tr>td:first-child{text-indent:104px;}
.tree-table .tr-level-4:before{content:'';position:absolute;left:0;top:-1px;bottom:0;width:90px;border-top:2px solid #f2f2f2;border-bottom:2px solid #f2f2f2;}
.tree-table .tr-level-5:before{content:'';position:absolute;left:0;top:-1px;bottom:0;width:110px;border-top:2px solid #f2f2f2;border-bottom:2px solid #f2f2f2;}
/*树形表格组件左边的线*/
.tree-table .tr-level-2:after{content:'';position:absolute;left:21px;top:0;height:100%;/*bottom:0;*/border-left:1px solid #CAD6E1;}
.tree-table .tr-level-1 .tr-level-2:last-child:after{top:0;height:21px;}
.tree-table .tr-level-1 .tr-level-2.last-child:after{top:0;height:21px;}
.tree-table .tr-level-3:after{content:'';position:absolute;left:41px;top:0;height:100%;border-left:1px solid #CAD6E1;}
.tree-table .tr-level-2 .tr-level-3:last-child:after{top:0;height:21px;}
.tree-table .tr-level-2 .tr-level-3.last-child:after{top:0;height:21px;}
.tree-table .tr-level-4:after,.tree-table .tr-level-5:after{content:'';position:absolute;left:61px;top:0;height:100%;border-left:1px solid #CAD6E1;}
.tree-table .tr-level-5:after{left:80px;}
.tree-table .tr-level-3 .tr-level-4:last-child:after{top:0;height:21px;}
.tree-table .tr-level-4 .tr-level-5:last-child:after{top:0;height:21px;}
.tree-table .tr-level-3 .tr-level-4.last-child:after{top:0;height:21px;}
.tree-table .tr-level-4 .tr-level-5.last-child:after{top:0;height:21px;}
.tree-table .tr-level-2 tr>td:first-child{background:url(../img/common/treetable-line.png) no-repeat 21px -55px;}
.tree-table .tr-level-2 tr>td.active:first-child{background-position:21px -5px;}
.tree-table .tr-level-3 tr>td:first-child{background-position:41px -55px;}
.tree-table .tr-level-3 tr>td.active:first-child{background-position:41px -5px;}
.tree-table .tr-level-4 tr>td:first-child{background-position:60px -55px;}
.tree-table .tr-level-5 tr>td:first-child{background-position:80px -55px;}
.tree-table .tr-level-4 tr>td.active:first-child{background-position:60px -5px;}
.tree-table .tr-level-5 tr>td.active:first-child{background-position:80px -5px;}
.tree-table .fold-click{cursor:pointer;}
.tree-table .fold-click>.arrow-icon{display:inline-block;vertical-align:middle;width:23px;height:20px;background:url(../img/common/sprite-up.png) no-repeat -1px 0;cursor:pointer;}
.tree-table .fold-click.active>.arrow-icon{background-position:-22px 0;}
3.js

// 折叠表格数组件
$(document).on('click','.tree-table .fold-click',function (e) {
if($(this).hasClass('active')){
$(this).toggleClass('active').closest('table').nextAll().children().slideUp();
}
else{
$(this).toggleClass('active').closest('table').nextAll().children().slideDown();
}
});
// 给每一层级的最后一行添加last-child类,兼容ie8左侧线条
$(".tree-table .tr-level-1 .tr-level-2:last-child,.tree-table .tr-level-2 .tr-level-3:last-child,.tree-table .tr-level-3 .tr-level-4:last-child,.tree-table .tr-level-4 .tr-level-5:last-child").addClass('last-child');
附图:

————————————————
版权声明:本文为CSDN博主「低_调_哥」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/caiyongshengcsdn/article/details/79308555

css折叠表格的更多相关文章

  1. CSS控制表格(table)样式

    CSS控制表格样式 /* 合并边框重叠部分 */ table{border-collapse:collapse;} /* 单元格边框 */ td{border:1px solid #A7AEB1;}

  2. 四个好看的CSS样式表格

    文章来源 http://www.cnphp6.com/archives/58020 1. 单像素边框CSS表格 这是一个非经常常使用的表格样式. 源码: 2. 带背景图的CSS样式表格 和上面差点儿相 ...

  3. 常用的四种CSS样式表格

    1. 单像素边框CSS表格 这是一个很常用的表格样式. [html] <style type="text/css"> table.gridtable { font-fa ...

  4. 巧妙使用div+css模拟表格对角线

    首先声明: 这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点.如果对此深以为然的朋友,请一笑过之... 有时在插入文档时,要用到表格对角线,常见 ...

  5. 折叠表格思路及遇到的问题(tableView:viewForHeaderInSection:的section从1开始,不是从0开始)

    项目需要做了一个类似qq联系人的折叠表格,思路很简单:设置每个section的header,在header上显示组名等信息,然后根据折叠与否,设置每个section中cell的数量,如果折叠,则将之设 ...

  6. 问题:table 可否实现对角线;结果:用div+css模拟表格对角线

    首先声明: 这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点.如果对此深以为然的朋友,请一笑过之... 有时在插入文档时,要用到表格对角线,常见 ...

  7. CSS控制表格嵌套

    网页设计应用中,当我们不能完全放弃表格的使用时,为了达到预期的效果,不免要用到表格嵌套(特别是多层嵌套)方式来进行布局.可能很多同仁都遇到过这样的问题,为了达到显示效果要为每一个(每一层)的表格写不同 ...

  8. 学习笔记 第九章 使用CSS美化表格

    第9章  使用CSS美化表格 学习重点 正确使用表格标签: 设置表格和单元格属性: 设计表格的CSS样式. 9.1 表格的基本结构 表格由行.列.单元格3部分组成,单元格时行与列交叉的部分. 在HTM ...

  9. html table 美化-html如何用css美化表格

    html用css美化表格的方法:首先创建一个HTML示例文件:然后在body中创建table表格:最后通过style标签给表格添加css样式即可. 代码 下面通过示例来看看. /*表格样式*/ tab ...

随机推荐

  1. VNC Viewer配置

    VNC概述 VNC (Virtual Network Computing)是虚拟网络计算机的缩写.VNC 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的.VNC 是在 ...

  2. 三、SpringBoot启动时JDBC报错:You must configure either the server or JDBC driver (via the serverTimezone configuration property)

    错误提示: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connectio ...

  3. Node JS复制文件

    /** * Created by Administrator on 2019/11/6. *指尖敲打着世界 ----一个阳光而又不失帅气的少年!!!. */ var fs=require(" ...

  4. springboot实现内存缓存

    题记:实现缓存大部分可以使用redis实现,简单.便捷,redis在针对应用部署多服务器是很好的,但如果针对单一服务器,内存缓存更好. 1.创建CacheLoader.java import java ...

  5. Postman系列之发送请求(一)

    实验简介 Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件.它能提供功能强大的 Web API 和 HTTP 请求的调试,它能够发送任何类型的HTTP 请求 (GET, ...

  6. java集合(List,Set,Map)详细总结

    一,集合的由来: 数组是长度是固定的,当添加的元素超过数组的长度时需要对数组重新定义,太麻烦了,java内部给我们提供了集合类,能存储任意对象,长度是可以改变的,随着元素的增加而增加,随着元素的减少而 ...

  7. Nginx 日志打印POST数据

    在工作中,开发希望能从Nginx日志中获取POST的数据信息,先记录下来 在日志格式后面加上 $request_body 配置信息 log_format main '$remote_addr - $r ...

  8. django基础窗口类的使用

    django基础窗口form表单的运用 具体效果图如下: 首先确定表单中的数据集,先自己创建一个forms.py或者在原来的models.py中添加: 1代码如下 class ContactForm( ...

  9. 【ABAP系列】SAP ABAP如何在调试查看EXPORT/IMPORT 内存数据

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP如何在调试查看E ...

  10. json字段为null时输出空字符串

    Map < String , Object > jsonMap = new HashMap< String , Object>(); jsonMap.put(); jsonMa ...