我需要同时拥有固定的表头和列。
我想在特定时间显示一个可滚动的表格,并拥有固定的表头(第一行)和列。
- 左侧包含表头列
- 右侧包含表头行和表格
重要提示:
- 当数据向水平方向移动时:固定表头(第一行将相应移动)
- 当数据向垂直方向移动时:固定列(第一列将相应移动)
这将使我能够水平滚动而不会使表头列移动,垂直滚动而不会使表头行移动(我猜是通过其父元素内的绝对定位实现?)。
附注:我已经搜寻了很多,但找到的都只有固定的表头或固定的第一列。我想同时拥有两者。 这里是包含固定列的fiddle,请帮助我添加固定表头(第一行)。
fiddle: http://jsfiddle.net/cfr94p3w/
Html代码:
<div class="table-container">
<div class="headcol">
<table>
<thead>
<th>Room</th>
</thead>
<tbody>
<tr>
<td>Fooname</td>
</tr>
<tr>
<td>Barname</td>
</tr>
<tr>
<td>Barfoo</td>
</tr>
<tr>
<td>Zorzor</td>
</tr>
<tr>
<td>Lorname Ipsname</td>
</tr>
</tbody>
</table>
</div>
<div class="right">
<table>
<thead>
<th>8-10</th>
<th>10-12</th>
<th>12-14</th>
<th>14-16</th>
<th>16-18</th>
<th>18-20</th>
</thead>
<tbody>
<tr>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell booked">Already booked</td>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell available">Available for booking</td>
</tr>
<tr>
<td class="cell available">Available for booking</td>
<td class="cell booked">Already booked</td>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
</tr>
<tr>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell booked">Already booked</td>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell available">Available for booking</td>
</tr>
<tr>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell available">Available for booking</td>
<td class="cell available">Available for booking</td>
<td class="cell booked">Already booked</td>
<td class="cell booked">Already booked</td>
</tr>
<tr>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
<td class="cell booked">Already booked</td>
<td class="cell booked">Already booked</td>
<td class="cell booked">Already booked</td>
<td class="cell available">Available for booking</td>
</tr>
</tbody>
</table>
</div>
</div>
谢谢,祝您有愉快的一天。