[BS4] Bootstrap4 Customize Responsive Table(客制化表格寬度)
tags: table
, table-responsive
, customization
Table 是報表、數據等資料很常使用的程式方式。在 Bootstrap4 中 Table 的結構其實還蠻單純的,但是有些時候直接套用的表格卻不是這麼的「好看」,它會隨著內容的寬度而對每個欄寬造成不同的影響,進而使得版面變得不太好看,因此,讓我們來試著深入一些些瞭解 Bootstrap Table ,看可以做哪些操作,客制化成我們想要的好看表格。
這篇文章主要說明如何把 Bootstrap 的表格調整成自己想要的樣式,關於 Bootstrap 表格的基本架構可以參考中文官方文件。
以下內容建議搭配 範例程式碼 @ CodePen 閱讀。
基本架構
Bootstrap 4 表格的基本架構如下,其他 <th>
標籤可以搭配 scope
屬性使用,屬性值可以是 col
, row
, colgroup
, rowgroup
,主要是用來說明這個 th 是屬於某欄或某列的標頭。
另外,Bootstrap 4 還提供其他可套用的 class:
<table>
:.table-dark
,.table-sm
,.table-striped
,.table-bordered
,.table-hover
<thead>
:.thead-light
,.thead-dark
<tr>
,<td>
:.table-active
,.table-primary
,.table-secondary
,.table-success
,.table-danger
,.table-warning
,.table-info
,.table-light
,.table-dark
HTML <th> scope Attribute @ w3schools
<!-- HTML -->
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Username</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>