2
我正在尋找一個如何保持固定的<thead>
和可滾動的<tbody>
的CSS示例。我搜索了很多例子,但都沒有工作。Scrollable tbody
我該如何讓這個簡單的桌面保持固定,並且要滾動表體。每當我嘗試在單個元素下面「擠壓」身體或不在50px高度內滾動時。
HTML:
<table id='recipient-summary'>
<thead class='fixed'>
<tr>
<th>Live</th>
<th>Paid</th>
<th>Dep</th>
<th>Tran</th>
<th>Date & Time</th>
<th>Type</th>
<th>Name</th>
<th>Total</th>
</tr>
</thead>
<tbody class='scrollable'>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
</tbody>
<tfoot></tfoot>
</table>
CSS:
thead,tbody{ display:block; }
tbody{ height:50px; overflow:auto; }
td{ border:1px solid #777; padding:5px; }
你必須檢查這個URL。 http://www.imaputz.com/cssStuff/bigFourVersion.html –
它很糟糕,但訣竅是你必須在每個表格的列上設置明確的寬度('td:nth-child(k)'和'th :nth-child(k)') –
這裏有很多討論的類似問題http://stackoverflow.com/questions/17067294/html-table-with-100-width-with-vertical-scroll-inside-tbody may help你 –