【发布时间】:2019-07-11 08:30:08
【问题描述】:
在阅读了许多关于使用带有滚动 tbody 的固定 theader 的帖子后,大多数答案都指向调整 tbody 以显示:块。但是,显示块使我在右侧的列在列越向右时对齐。我正在处理动态数据,所以有时我的表格会呈现 16 列,但有时最多可能有 25 列。我希望所有列正确对齐,同时保持一个带有可滚动 tbody 的固定头。这是我的 CSS:
table {
overflow: hidden;
width: 100%;
height: 810px;
table-layout: fixed;
display: flex;
flex-direction: column;
align-items: center;
overflow: hidden;
}
thead,
tbody {
width: 100%;
}
tbody {
flex: 1;
overflow-y: scroll;
width: 100%;
}
th {
cursor: pointer;
}
th {
}
td {
display: flex;
justify-content: center;
}
td,
th {
padding: 0;
}
tr {
width: 100%;
display: flex;
}
tr th {
flex: 1;
}
tr td {
flex: 1;
}
这是一个小的 Codepen 示例:https://codepen.io/anon/pen/xMmqxK
Codepen 偏斜没有我网站上的偏斜那么突出,因此有点难以察觉。任何帮助将非常感激。如果我发布了屏幕截图,您将能够看到更多问题,但是,由于公司环境,我不能。再次感谢。
【问题讨论】:
标签: html css html-table flexbox