sticky定位支持表格头实例页面

回到相关文章 »

效果:

标题1 标题2 标题3 标题4 标题5 标题6 标题7 标题8 标题9 标题10
                 
                 

代码:

CSS代码:
.box {
    max-width: 500px;
    height: 250px;
    word-break: keep-all;
    overflow: auto;
}
table, th, td {
    border-collapse: collapse;
    border: 1px solid;    
}
.header th {
    background-color: #ddd;
    position: sticky;
    top: 0;
}
HTML代码:
<div class="box">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="header">
    <th scope="col">标题1</th>
    <th scope="col">标题2</th>
    <th scope="col">标题3</th>
    <th scope="col">标题4</th>
    <th scope="col">标题5</th>
    <th scope="col">标题6</th>
    <th scope="col">标题7</th>
    <th scope="col">标题8</th>
    <th scope="col">标题9</th>
    <th scope="col">标题10</th>
  </tr>
  <tr>
    <td><img src="1.jpg"></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    ... 同上
  </tr>
</table>
</div>