使用css让表头固定的方法
1、可以使用display: table; width: 100%; table-layout: fixed;
table-layout: fixed;设置表格布局算法。tableLayout 属性用来显示表格单元格、行、列的算法规则。
详细可见:https://www.w3school.com.cn/cssref/pr_tab_table-layout.asp
https://www.w3school.com.cn/tiy/t.asp?f=csse_table_table-layout
<div>
<div class="table-head">
<table id="contentTable">
<thead>
<tr>
<th><input type="checkbox"/></th>
<th>xxxxx</th>
<th>xxxxx</th>
<th>证件号码</th>
<th>姓名</th>
<th>性别</th>
<th>xxxxx</th>
<th>出生日期</th>
<th>xxx</th>
<th>xxx</th>
<th>ssss</th>
<th>xxxx</th>
<th>ccccc手机</th>
<th>家庭住址</th>
<th>xxxxx</th>
<th>xxxxx</th>
<th>xxxxx</th>
<th>修改日期</th>
</tr>
</thead>
<tbody>
<tr>
//21个td 省略
</tr>
</tbody>
</table>
</div>
</div>
这里是样式
/** 这是css */
body{overflow-y: hidden}
#contentTable tbody { display: block; height: 520px; overflow-y: scroll; }
#contentTable thead,
#contentTable tbody tr { display: table; width: 100%; table-layout: fixed; /**表格列的宽度由表格宽度决定,不由内容决定*/ text-align: center; } /**每一个th都要和对应的td宽度相同,如果不设置,则默认均分宽度,我设置的都是一些内容较多的,比如说身份证号码,电话,住址等*/
#contentTable tr th:nth-of-type(1),#contentTable tr td:nth-of-type(1){width: 1.5%;}
#contentTable tr th:nth-of-type(2),#contentTable tr td:nth-of-type(2){width: 8.5%;}
#contentTable tr th:nth-of-type(3),#contentTable tr td:nth-of-type(3){width: 7%;}
#contentTable tr th:nth-of-type(4),#contentTable tr td:nth-of-type(4){width: 8.5%;}
#contentTable tr th:nth-of-type(8),#contentTable tr td:nth-of-type(8){width: 5%;}
#contentTable tr th:nth-of-type(9),#contentTable tr td:nth-of-type(9){width: 5%;}
#contentTable tr th:nth-of-type(12),#contentTable tr td:nth-of-type(12){width: 8.5%;}
#contentTable tr th:nth-of-type(13),#contentTable tr td:nth-of-type(13){width: 6%;}
#contentTable tr th:nth-of-type(14),#contentTable tr td:nth-of-type(14){width: 15%;}
#contentTable tr th:nth-of-type(16),#contentTable tr td:nth-of-type(16){width: 5%;}
#contentTable tr th:nth-of-type(18),#contentTable tr td:nth-of-type(18){width: 5%;} /**这一个重要:写完上面的看效果应该是表头和内容对不齐。我们需要的是调节0.4em中的0.4,试着变大变小就能看到区别,我试了,刚好跳到0.4,所有的列都能垂直对齐*/
#contentTable thead { width: calc( 100% - 0.4em);/*表头与表格垂直对齐*/ }
这里如果不需要右侧滚动条的时候,
#sTable::-webkit-scrollbar{
width:0px;
opacity:0;
-webkit-overflow-scrolling: touch;
}
使用css让表头固定的方法的更多相关文章
- div+css实现表头固定内容滚动表格
<div class="m-demo"> <table> <thead> <tr><th>定宽a</th>& ...
- html css 如何将表头固定(转)
html css 如何将表头固定 position属性取值为fixed时,则元素的位置将不受滚动条的影响,而是直接依据窗口定位,这就是将表头固定的最直接方法,网上其他途径感觉都是在走弯路.但是与此同时 ...
- 纯CSS实现table表头固定(自创备忘)
因为之前约定时候产品没说要表头固定,这次迭代测试突然提出这个需求,而且不知道因为什么未知原因非要这样不可--因为之前用了table标签做表单,而且也没用插件,这下就难了点,找另外一个前端前辈妹子商量了 ...
- html css 如何将表头固定
position属性取值为fixed时,则元素的位置将不受滚动条的影响,而是直接依据窗口定位,这就是将表头固定的最直接方法,网上其他途径感觉都是在走弯路.但是与此同时必须解决两个问题.第一:表体将随之 ...
- css手写一个表头固定
Bootstrap,layui等前端框架里面都对表头固定,表格滚动有实现,偏偏刚入职的公司选择了手动渲染表格,后期又觉得表格数据拉太长想要做表头固定.为了避免对代码改动太大,所以决定手写表头固定 主要 ...
- html bootstrap 表头固定在顶部,表列 可以自由滚动的效果
该效果主要是依照 bootstrap 的一个样式,class="navbar-fixed-top"; 参考网址为:http://v3.bootcss.com/components/ ...
- IE的表头固定/表头不动(使用expression)
本文主要介绍在IE浏览器中,实现表头固定的一种方法.这种方法使用到了 IE 浏览器特有的 expression 方法. 表头固定DEMO1 主要代码: <style type="tex ...
- 【转】CSS z-index 属性的使用方法和层级树的概念
文章转自:CSS z-index 属性的使用方法和层级树的概念,另外加了一点自己的注释 CSS 中的 z-index 属性用于设置节点的堆叠顺序, 拥有更高堆叠顺序的节点将显示在堆叠顺序较低的节点前面 ...
- css实现居中的五中方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- Sublime Text 编译运行Kotlin
Sublime Text 编译运行Kotlin 转 https://blog.csdn.net/pirate7777777/article/details/72655293 kotlin最近是火了,所 ...
- IO注意事项
read()方法返回值为什么是int? 因为字节输入流可以操作任意类型的文件,比如图片音频等,这些文件底层都是以二进制形式的存储的,如果每次读取都返回byte,有可能在读到中间的时候遇到1111111 ...
- 用ConfigMap管理配置(10)
一.ConfigMap介绍管理配置: ConfigMap介绍 Secret 可以为 Pod 提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如应用的配置信息,则可以用 ConfigMa ...
- k8s管理机密信息(9)
一.启动应用安全信息的保护: Secret介绍: 应用启动过程中可能需要一些敏感信息,比如访问数据库的用户名密码或者秘钥.将这些信息直接保存在容器镜像中显然不妥,Kubernetes 提供的解决方案是 ...
- Android开发环境搭建(eclipse版)
1.下载安装JDK 网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
- 【ARM-Linux开发】Linux下更改目录下所有文件的所有者及其权限
[ARM-Linux开发]Linux下更改目录下所有文件的所有者及其权限 chown 更换所有者: chmod 改变权限: 想一次修改某个目录下所有文件的权限,包括子目录中的文件权限也要修改,要使用参 ...
- Java学习笔记-枚举类
实例有限且固定的类成为枚举类 枚举类的实现 早期时候的实现形式: public static final int SEASON_SPRING = 1; public static final int ...
- js 监听音频视频控件是否播放
监听onplaying: var myVideo=document.getElementById("video1"); myVideo.addEventListener(" ...
- python一些小知识点is和编码
dic = { "name":["alex", "wusir", "taibai"], 'py9':{ "ti ...
- [CF261E]Maxim and Calculator_搜索_欧拉筛素数_动态规划
Maxim and Calculator 题目链接:https://www.luogu.org/problem/CF261E 数据范围:略. 题解: 考试的时候只会暴力,学弟太强了$\%\%\% Or ...