css 设置冻结表格头,纯CSS冻结表头

css

/* Colors */

/* Bidirectional Table */

div.frozen-table {

width: 100%;

min-height: 150px;

overflow: scroll;

margin: 0 auto;

/* Remove the below 3 properties on your Website (Test-Purpose) */

width: 800px;

height: 400px;

resize: both;

}

div.frozen-table table {

min-width: 100%;

min-height: 100%;

border-collapse: collapse;

}

div.frozen-table table th {

height: 100%;

border: 0px none transparent;

padding: 0;

}

div.frozen-table table th span {

display: block;

padding: 20px;

border-right: 1px solid #2d5aff;

}

div.frozen-table table thead tr th {

background: #2d5aff;

color: #ffffff;

position: relative;

z-index: 0;

}

div.frozen-table table thead tr:first-child th span {

border: 0px none transparent;

}

div.frozen-table table thead tr:first-child th:first-child {

background: #000000;

}

div.frozen-table table tbody th {

background: #ffffff;

}

div.frozen-table table tbody th:only-child {

z-index: -1;

}

div.frozen-table table tbody th:only-child span {

border: 0px none transparent;

border-top: 1px solid #2d5aff;

border-bottom: 1px solid #2d5aff;

}

div.frozen-table table tbody td {

background-color: #ffffff;

padding: 20px;

}

div.frozen-table[data-table="top"] thead th, div.frozen-table[data-table="both"] thead th {

position: -webkit-sticky;

position: sticky;

top: 0;

}

div.frozen-table[data-table="left"] tbody th, div.frozen-table[data-table="both"] tbody th {

position: -webkit-sticky;

position: sticky;

left: 0;

z-index: 1;

}

div.frozen-table[data-table="left"] thead th:first-child, div.frozen-table[data-table="both"] thead th:first-child {

position: -webkit-sticky;

position: sticky;

left: 0;

z-index: 2;

}

/* Some CSS to prettyfy the screen */

body {

text-align: center;

font-family: Arial, sans-serif;

margin: 0;

min-height: 100vh;

position: relative;

z-index: 1;

overflow: hidden;

overflow-y: auto;

background: linear-gradient(180deg, #ffc171 0%, #ff752d 100%);

background-repeat: no-repeat;

}

body:after {

content: " ";

display: block;

width: 100%;

height: 100%;

position: absolute;

left: 0;

top: 0;

z-index: -1;

opacity: .8;

background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="28" height="49" viewBox="0 0 28 49"%3E%3Cg fill-rule="evenodd"%3E%3Cg id="hexagons" fill="%239C92AC" fill-opacity="0.4" fill-rule="nonzero"%3E%3Cpath d="M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');

}

body #main-wrapper {

padding: 40px 0;

}

body .contrast-bg {

padding: 15px;

background-color: rgba(255, 255, 255, 0.6);

margin-bottom: 60px;

}

body .contrast-bg p {

margin-top: 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要插入一个好看的表头表格,首先我们可以使用HTML和CSS来完成。下面是一个简单的示例: HTML部分: ``` <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <table> <thead> <tr> <th>姓名</th> <th>年龄</th> <th>性别</th> </tr> </thead> <tbody> <tr> <td>张三</td> <td>25</td> <td>男</td> </tr> <tr> <td>李四</td> <td>30</td> <td>女</td> </tr> </tbody> </table> </body> </html> ``` CSS部分(style.css文件): ``` table { border-collapse: collapse; width: 100%; } thead { background-color: #f2f2f2; } th, td { text-align: left; padding: 8px; } tr:nth-child(even) { background-color: #f9f9f9; } ``` 在上述示例中,我们使用了HTML中的`<table>`标签来创建表格,使用`<thead>`标签来定义表头表头中的每个表头单元格使用`<th>`标签来定义。表格的内容则放在`<tbody>`标签中,每一行使用`<tr>`标签来定义,每个单元格使用`<td>`标签来定义。 CSS部分定义了表格的样式。`border-collapse: collapse;`用于去掉单元格之间的边框,`width: 100%;`使得表格占满父容器的宽度。`thead`的背景颜色设置为灰色,`th, td`的样式设置了单元格的文本对齐方式和内边距,`tr:nth-child(even)`为奇偶行设置不同的背景颜色,以增加可读性。 以上是一个简单的示例,你可以根据自己的需求继续完善表头表格的样式,例如添加边框、调整字体样式等。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值