如何设置<table>
100%宽度并仅在<tbody>
垂直滚动内放置一些高度?
table {
width: 100%;
display:block;
}
thead {
display: inline-block;
width: 100%;
height: 20px;
}
tbody {
height: 200px;
display: inline-block;
width: 100%;
overflow: auto;
}
Run Code Online (Sandbox Code Playgroud)
<table>
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
<th>Head 4</th>
<th>Head 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content 1</td>
<td>Content 2</td>
<td>Content 3</td>
<td>Content 4</td>
<td>Content 5</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我希望避免增加一些额外的div,我要的是简单的表像这样,当我试图改变显示table-layout
,position
在CSS表以及更多的东西没有工作好与100%的宽度仅与PX固定宽度.