gpt4 book ai didi

css - 带有固定标题的引导表 - Angular 5

转载 作者:行者123 更新时间:2023-11-28 01:38:11 25 4
gpt4 key购买 nike

我用 HTML 创建了一个表格,我想显示它的标题是固定的(滚动只会影响正文)。

我找到了一个解决方案,它几乎可以正常工作。

tbody {
display:block;
height:500px;
overflow:auto;
}
thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;/* even columns width , fix width of table too*/
}
thead {
width: calc( 100% - 1em )/* scrollbar is average 1em/16px width, remove it from thead width */
}
table {
width:400px;
}

问题是使用属性 table-layout: fixed,它固定了列的宽度,所以我的列没有正确显示(它们重叠):

enter image description here

我该如何解决?我已经尝试过 table-layout 的四个可能值

最佳答案

使用td {word-wrap: break-word;}

tbody {
display:block;
height:500px;
overflow:auto;
}
thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;/* even columns width , fix width of table too*/
}
td{
word-wrap: break-word;
}
thead {
width: calc( 100% - 1em )/* scrollbar is average 1em/16px width, remove it from thead width */
}
table {
width:400px;
}
<table class="a">
<thead>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</thead>
<tbody>
<tr>
<td>AlfredsFutterkisteghrtrh</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</tbody>
</table>

关于css - 带有固定标题的引导表 - Angular 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50563882/

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