1 回答
TA贡献1830条经验 获得超9个赞
非常简单:
<th>的样式设置为sticky,
top: 0粘在顶部,并
background-color: white“隐藏”滚动行。
nowrap用于水平效果(非必需)。
th {
position: sticky;
top: 0;
background-color: white;
}
<table border="1">
<tr>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
<th>sticky blah blah blah sticky </th>
</tr>
<tr>
<td nowrap>normal blah blah blah normal 01</td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
<td nowrap>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 02</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 03</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 04</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 05</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 06</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 07</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 08</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 09</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 10</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 11</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 12</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 13</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 14</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 15</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 16</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 17</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 18</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 19</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 20</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 21</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 22</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 23</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 24</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 25</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 26</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 27</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 28</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 29</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 30</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 31</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 32</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 33</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 34</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 35</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 36</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 37</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 38</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 39</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
<tr>
<td>normal blah blah blah normal 40</td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
<td>normal blah blah blah normal </td>
</tr>
</table>
添加回答
举报