Tailwind CSS 表格布局

2022-08-12 09:29 更新

表格布局

用于控制表格布局算法的功能類。

Class
Properties
table-auto table-layout: auto;
table-fixed table-layout: fixed;

Auto

使用 ?table-auto? 允許表格自動調(diào)整列的大小以適應(yīng)單元格的內(nèi)容。


<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

使用 ?table-fixed? 允許表格忽略內(nèi)容,使用固定的列寬。第一行的寬度將設(shè)置整個表格的列寬。

您可以手動設(shè)置一些列的寬度,其余的可用寬度將被平均分配給沒有明確寬度的列。


<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>

自定義

變體

默認情況下, 針對 table layout 功能類,只生成 responsive 變體。

您可以通過修改您的 ?tailwind.config.js? 文件中的 ?variants ?部分中的 ?tableLayout ?屬性來控制為 table layout 功能生成哪些變體。

例如,這個配置也將生成 hover and focus 變體:

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

禁用

如果您不打算在您的項目中使用 table layout 功能,您可以通過在配置文件的 ?corePlugins ?部分將 ?tableLayout ?屬性設(shè)置為 ?false ?來完全禁用它們:

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


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號