我需要一個帶滾動的tbody,並且thead不應該有滾動。所以在這樣做的時候,thead的寬度會減小到thead中文本的大小。thead的寬度不同於tbody
有沒有一種方法,使THEAD寬度尺寸相同的tbody
這就是我。 https://jsfiddle.net/Viraj173/jqwgkq8k/
CSS
tbody.scroll{
overflow-y: auto;
height:100px;
position: absolute;
}
th {
color: #ffffff;
background: #373d49;
padding: 5px;
text-align: left;
font-size: 14px;
}
HTML
<table >
<thead>
<tr>
<th>
Value
</th>
</tr>
</thead>
<tbody class="scroll">
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
<tr>
<td>
Setting Value 1
</td>
</tr>
</tbody>
</table>
我添加靜態寬度在桌子上,THEAD並在CSS的,你已經將它設置爲位置TBODY:絕對的; https://jsfiddle.net/jqwgkq8k/1/ – Gezzasa