html table顯示滾動條
阿新 • • 發佈:2021-01-12
實現思路
通過限制height後顯示滾動條;將thead部分拆出單獨排版即可;thead部分採用了boostrap排版,tbody部分採用了寬度百分比排版
具體實現
層級結構:
+div
++標題部分
+div
++div
++table
注意:
兩層div包裹table
<style> .list-task-plan-light{ background-color: #898989; } .list-task-plan-title span{ border-left: 2px solid black; line-height: 1; } .list-task-plan-title span:first-child{ border-left: 0; } .list-task-plan-body td{ font-size: 10px; text-align: center; } /* 主要樣式 */ .plan-table-div{ position:relative; } .plan-table-table{ height:100px; overflow:auto; } </style> <div class="list-task-plan-title list-task-plan-light d-flex"> //thead部分 <div class="col-11 d-flex justify-content-around"> <span class="col-2">序號</span> <span class="col-4">xxx</span> <span class="col-4">xxx</span> <span class="col-2">xxx</span> </div> <span class="col-1"> <a href="#"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16"> <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456l-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/> <path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/> </svg> </a> </span> </div> <div class="plan-table-div"> <div class="plan-table-table"> <table class="w-100"> <tbody> <tr> <td style="width: 20%">1</td> <td style="width: 40%">113°47''23.953E</td> <td style="width: 20%">113°47''23.953E</td> <td style="width: 20%">8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> <tr> <td>1</td> <td>113°47''23.953E</td> <td>113°47''23.953E</td> <td>8.0Kn</td> </tr> </tbody> </table> </div> </div>
最終效果圖:
參考連結:
http://jsfiddle.net/TweNm/
這個佈局並沒有將標題部分單獨拆出,而是採用定位的方式向上移動