在表头中添加一个额外的单元格,并将其合并为与表格中实际单元格数量相同的单元格。将这个额外的单元格加上宽度和边框属性,以实现固定表头的效果。以下为示例代码:
名称 | 日期 | 价格 | 描述 | |
---|---|---|---|---|
商品1 | 2022-01-01 | $20.00 | 这是商品1的描述内容 | |
商品2 | 2022-01-02 | $25.00 | 这是商品2的描述内容 | |
商品3 | 2022-01-03 | $30.00 | 这是商品3的描述内容 | |
商品4 | 2022-01-04 | $35.00 | 这是商品4的描述内容 |
.fixheader { width: 100%; border-collapse: separate; border-spacing: 0; }
.fixheader th, .fixheader td { padding: 5px; text-align: left; white-space: nowrap; }
.fixheader th:last-child { width: 17px; border-right: none; }
.fixheader th:first-child, .fixheader th:last-child { background-color: #F2F2F2; border-bottom: 2px solid #CCC; }
.fixheader th:first-child { position: sticky; top: 0; z-index: 2; }
上一篇:表头筛选值的单元格验证列表
下一篇:表头数据排成一条直线