Table Layout

Utilities for controlling the table layout algorithm.

Default class reference

Class
Properties
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.

Table Layout - 图1

  1. <table class="table-auto">
  2. <thead>
  3. <tr>
  4. <th>Title</th>
  5. <th>Author</th>
  6. <th>Views</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr>
  11. <td>Intro to CSS</td>
  12. <td>Adam</td>
  13. <td>858</td>
  14. </tr>
  15. <tr class="bg-emerald-200">
  16. <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
  17. <td>Adam</td>
  18. <td>112</td>
  19. </tr>
  20. <tr>
  21. <td>Intro to JavaScript</td>
  22. <td>Chris</td>
  23. <td>1,280</td>
  24. </tr>
  25. </tbody>
  26. </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.

Table Layout - 图2

  1. <table class="table-fixed">
  2. <thead>
  3. <tr>
  4. <th class="w-1/2 ...">Title</th>
  5. <th class="w-1/4 ...">Author</th>
  6. <th class="w-1/4 ...">Views</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr>
  11. <td>Intro to CSS</td>
  12. <td>Adam</td>
  13. <td>858</td>
  14. </tr>
  15. <tr class="bg-blue-200">
  16. <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
  17. <td>Adam</td>
  18. <td>112</td>
  19. </tr>
  20. <tr>
  21. <td>Intro to JavaScript</td>
  22. <td>Chris</td>
  23. <td>1,280</td>
  24. </tr>
  25. </tbody>
  26. </table>

Customizing

Variants

By default, only responsive variants are generated for table layout utilities.

You can control which variants are generated for the table layout utilities by modifying the tableLayout property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. extend: {
  5. // ...
  6. + tableLayout: ['hover', 'focus'],
  7. }
  8. }
  9. }

Disabling

If you don’t plan to use the table layout utilities in your project, you can disable them entirely by setting the tableLayout property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + tableLayout: false,
  6. }
  7. }

←Border Collapse Transition Property→

Edit this page on GitHub