将 table-layout:fixed
添加到表格中,将 display:table
添加到 thead 中可以解决你的问题。
修改后的 CSS:
table thead {
display:table;
width: 100%;
background-color: lightblue;
position: fixed;
}
table{
table-layout:fixed;
}
不过,这种方法有点笨拙,因为table-layout:fixed
会影响整个布局,并且可能无法达到您想要的效果。
您还可以为列设置百分比宽度,而不是使用table-layout:fixed
,以更好地控制布局。