法一:
用2个table:
<table width="300" border="0" cellpadding="0" cellspacing="1" bgcolor="#0099CC"> <tr> <th width="25%" nowrap><font color="#FFFFFF"> 123 </th> <th width="25%" nowrap><font color="#FFFFFF"> 456 </th> <th width="25%" nowrap><font color="#FFFFFF"> 789 </th> <th width="25%" nowrap><font color="#FFFFFF"> abc </th> </tr> </table> <span style="overflow-y:auto;height:100px;320px"> <table width="300" border="0" cellpadding="0" cellspacing="1" bgcolor="#0099CC"> <tr bgcolor="#FFFFFF"> <td width="25%"> 1</td> <td width="25%"> 4</td> <td width="25%"> 7</td> <td width="25%"> a</td> </tr> <tr bgcolor="#FFFFFF"> <td > 2</td> <td > 5</td> <td> 8</td> <td> b</td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> <tr bgcolor="#FFFFFF"> <td> 3 </td> <td> 6 </td> <td> 9 </td> <td > c </td> </tr> </table> </span>
法二:
1,把tbody设置成display:block,然后就对其高度设置一个固定值,overflow设置成auto。
2,把thead的tr设置成display:block。
3,因为都设置成block所以要给td手动添加宽度 200px
<table class="table"> <thead> <tr> <th>Id</th> <th>Name</th> <th>Category</th> <th>MonthAmount</th> <th>hasBackUp</th> <th>score</th> </tr> </thead> <tbody> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> <tr> <td>23</td> <td>South Bearing</td> <td>Glass/Material</td> <td>1234444</td> <td>TRUE</td> <td>3456.00</td> </tr> </tbody> </table>
View Code
.table thead tr { display:block; } .table tbody { display: block; height: 200px; overflow: auto; } .table th { width:20%; } .table td { width:20%; }
最新评论