「及時」模式:全新世代的 Tailwind CSS
Tailwind CSS on GitHub

Table Layout

Utilities for controlling the table layout algorithm.

Default class reference

Class
屬性
table-autotable-layout: auto;
table-fixedtable-layout: fixed;

Auto

Use table-auto to allow the table to automatically size columns to fit the contents of the cell.

Title Author Views
Intro to CSS Adam 858
A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design Adam 112
Intro to JavaScript Chris 1,280
<table class="table-auto">
  <thead>
    <tr>
      <th>Title</th>
      <th>Author</th>
      <th>Views</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Intro to CSS</td>
      <td>Adam</td>
      <td>858</td>
    </tr>
    <tr class="bg-emerald-200">
      <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
      <td>Adam</td>
      <td>112</td>
    </tr>
    <tr>
      <td>Intro to JavaScript</td>
      <td>Chris</td>
      <td>1,280</td>
    </tr>
  </tbody>
</table>

Fixed

Use table-fixed to allow the table to ignore the content and use fixed widths for columns. The width of the first row will set the column widths for the whole table.

You can manually set the widths for some columns and the rest of the available width will be divided evenly amongst the columns without explicit width.

Title Author Views
Intro to CSS Adam 858
A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design Adam 112
Intro to JavaScript Chris 1,280
<table class="table-fixed">
  <thead>
    <tr>
      <th class="w-1/2 ...">Title</th>
      <th class="w-1/4 ...">Author</th>
      <th class="w-1/4 ...">Views</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Intro to CSS</td>
      <td>Adam</td>
      <td>858</td>
    </tr>
    <tr class="bg-blue-200">
      <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
      <td>Adam</td>
      <td>112</td>
    </tr>
    <tr>
      <td>Intro to JavaScript</td>
      <td>Chris</td>
      <td>1,280</td>
    </tr>
  </tbody>
</table>

Customizing

Variants

默認情況下, 只有 響應式 的 table layout 變化模式 (variants) 會產生。

tailwind.config.jsvariants 區塊中變更 tableLayout 屬性來決定有哪些變化模式會生成。

舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       tableLayout: ['responsive', 'hover'],
      }
    }
  }

Disabling

如果你不打算在專案中使用 table layout 功能,可以在你的設定檔裡的 corePlugins 屬性中將 tableLayout 設定為 false 來停用功能:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     tableLayout: false,
    }
  }