gpt4 book ai didi

在 tbody 内垂直滚动的 html 表格

转载 作者:太空宇宙 更新时间:2023-11-04 14:58:27 25 4
gpt4 key购买 nike

我正在尝试在 tbody 内使用固定标题的垂直滚动条。我尝试了链接中提供的解决方案。

HTML table with 100% width, with vertical scroll inside tbody

table {
width: 100%;
border-spacing: 0;
}

thead, tbody, tr, th, td { display: block; }

thead tr {
/* fallback */
width: 97%;
/* minus scroll bar width */
width: -webkit-calc(100% - 16px);
width: -moz-calc(100% - 16px);
width: calc(100% - 16px);
}

tr:after { /* clearing float */
content: ' ';
display: block;
visibility: hidden;
clear: both;
}

tbody {
height: 100px;
overflow-y: auto;
overflow-x: hidden;
}

tbody td, thead th {
width: 19%; /* 19% is less than (100% / 5 cols) = 20% */
float: left;
}

如果出现滚动条就可以正常工作。但是如果行数很少并且没有出现滚动条,则说明 thead 没有与 tbody 对齐。如何解决 css 问题?

enter image description here

最佳答案

一旦您的 tbody 数据从指定高度移出,您的 y 轴就会被激活。

 tbody {
height: 50px;
display: inline-block;
width: 100%;
overflow-y:scroll;
}

关于在 tbody 内垂直滚动的 html 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38074727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com