Skip to content

CSS: table

.instui-table — 一個為 thtd 設計的樣式化資料表,可選附加標題,並支援懸停、固定與堆疊卡片布局。

對於 -layout-stacked,純 CSS 無法將每個欄位標題的文字拉入其儲存格,因此需為每個儲存格提供 data-label,堆疊卡片則藉由 ::before 顯示。個別部分請參見 table.headtable.bodytable.rowtable.celltable.col-headertable.row-header 成員。

Source: body.css

無障礙

<caption> 為表格標註,將欄位標題標記為 <th scope="col">、列標題標記為 <th scope="row">,在 -layout-stacked 中,由於標題列在視覺上隱藏,需為每個儲存格提供 data-label

使用方法

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/table.css";

範例

html
<table class="instui-table -hover">
  <caption>Top-rated films</caption>
  <thead>
    <tr>
      <th scope="col">Rank</th>
      <th scope="col">Title</th>
      <th scope="col">Year</th>
      <th scope="col">Rating</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>The Shawshank Redemption</td>
      <td>1994</td>
      <td>9.3</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>The Godfather</td>
      <td>1972</td>
      <td>9.2</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>The Godfather: Part II</td>
      <td>1974</td>
      <td>9.0</td>
    </tr>
  </tbody>
</table>

結構

text
.instui-table.-hover
  caption
  thead
    th
  tbody
    tr
      td, th[scope="row"]
flowchart TD n0[".instui-table.-hover"]:::cssdoc-root n1("caption"):::cssdoc-part n2("thead"):::cssdoc-part n3("th"):::cssdoc-part n4("tbody"):::cssdoc-part n5("tr"):::cssdoc-part n6("td, th[scope=&quot;row&quot;]"):::cssdoc-part n0 --> n1 n2 --> n3 n0 --> n2 n5 --> n6 n4 --> n5 n0 --> n4 classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

修飾器

修飾器說明
.-hover滑鼠懸停時標示列。@affects table.row — 保留並為列的懸停邊框上色。
.-layout-fixed固定表格佈局(等寬欄位)。
.-layout-stacked將每列堆疊為卡片,透過每儲存格的 data-label 實現。@affects table.head @affects table.body @affects table.row @affects table.cell @affects table.col-header @affects table.row-header — 將每個部分作為區塊堆疊,並相應隱藏/標註標題。

部件

部件說明
.caption一個可選的表格標題說明。

已使用的代幣

Token型別
--instui-component-table-background<color>LightDarklight-dark(#ffffff, #10141A)
--instui-component-table-cell-padding-horizontal<length>0.75rem
--instui-component-table-cell-padding-vertical<length>0.5rem
--instui-component-table-col-header-color<color>LightDarklight-dark(#273540, #F2F4F5)
--instui-component-table-color<color>LightDarklight-dark(#273540, #ffffff)
--instui-component-table-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-component-table-font-size<length>1rem
--instui-component-table-head-font-weight<integer>600

子元件