1. Tables
  2. table-layout

Tables

table-layout

用于控制表格布局算法的工具。

ClassStyles
table-auto
table-layout: auto;
table-fixed
table-layout: fixed;

示例

自动调整列宽

使用 table-auto 工具自动调整表格列以适应单元格内容:

SongArtistYear
The Sliding Mr. Bones (Next Stop, Pottersville)Malcolm Lockyer1961
Witchy WomanThe Eagles1972
Shining StarEarth, Wind, and Fire1975
<table class="table-auto">  <thead>    <tr>      <th>Song</th>      <th>Artist</th>      <th>Year</th>    </tr>  </thead>  <tbody>    <tr>      <td>The Sliding Mr. Bones (Next Stop, Pottersville)</td>      <td>Malcolm Lockyer</td>      <td>1961</td>    </tr>    <tr>      <td>Witchy Woman</td>      <td>The Eagles</td>      <td>1972</td>    </tr>    <tr>      <td>Shining Star</td>      <td>Earth, Wind, and Fire</td>      <td>1975</td>    </tr>  </tbody></table>

使用固定列宽

使用 table-fixed 工具忽略单元格内容,为每列设置固定宽度:

SongArtistYear
The Sliding Mr. Bones (Next Stop, Pottersville)Malcolm Lockyer1961
Witchy WomanThe Eagles1972
Shining StarEarth, Wind, and Fire1975
<table class="table-fixed">  <thead>    <tr>      <th>Song</th>      <th>Artist</th>      <th>Year</th>    </tr>  </thead>  <tbody>    <tr>      <td>The Sliding Mr. Bones (Next Stop, Pottersville)</td>      <td>Malcolm Lockyer</td>      <td>1961</td>    </tr>    <tr>      <td>Witchy Woman</td>      <td>The Eagles</td>      <td>1972</td>    </tr>    <tr>      <td>Shining Star</td>      <td>Earth, Wind, and Fire</td>      <td>1975</td>    </tr>  </tbody></table>

你可以手动为部分列设置宽度,其余的可用宽度将在未设置宽度的列间平均分配。第一行设置的宽度将应用于整张表。

响应式设计

Prefix a table-layout utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="table-none md:table-fixed ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

版权所有 © 2025 Tailwind Labs Inc.·商标政策