Table Layout

Utilities for controlling the table layout algorithm.

React propsCSS Properties
tableLayout={keyword}table-layout: {keyword};

Auto

Use tableLayout="auto" to allow the table to automatically size columns to fit the contents of the cell.

<> <template preview> <x.table tableLayout="auto" borderCollapse="collapse"> <thead> <tr> <x.th px={4} py={2} color="amber-600"> Title </x.th> <x.th px={4} py={2} color="amber-600"> Author </x.th> <x.th px={4} py={2} color="amber-600"> Views </x.th> </tr> </thead> <tbody> <tr> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > Another Story </x.td> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > James </x.td> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > 858 </x.td> </tr> <x.tr bg="amber-200"> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > The Unexpected very long Journey of a Hobbit in the Middle-Earth </x.td> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > James </x.td> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > 112 </x.td> </x.tr> <tr> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > A short story </x.td> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > Chris </x.td> <x.td border borderColor="amber-500" px={4} py={2} color="amber-600" fontWeight="medium" > 1,280 </x.td> </tr> </tbody> </x.table> </template> <x.table tableLayout="auto"> <thead> <tr> <th>Title</th> <th>Author</th> <th>Views</th> </tr> </thead> <tbody> <tr> <td>Another Story</td> <td>James</td> <td>858</td> </tr> <x.tr bg="light-blue-200"> <td> A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design </td> <td>James</td> <td>112</td> </tr> <tr> <td>A short story</td> <td>Chris</td> <td>1,280</td> </x.tr> </tbody> </x.table> </>

Fixed

Use tableLayout="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.

<> <template preview> <x.table tableLayout="fixed" borderCollapse="collapse"> <thead> <tr> <x.th px={4} py={2} color="light-blue-600" w={0.5}> Title </x.th> <x.th px={4} py={2} color="light-blue-600" w={0.25}> Author </x.th> <x.th px={4} py={2} color="light-blue-600" w={0.25}> Views </x.th> </tr> </thead> <tbody> <tr> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > Another Story </x.td> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > James </x.td> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > 858 </x.td> </tr> <x.tr bg="light-blue-200"> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > The Unexpected very long Journey of a Hobbit in the Middle-Earth </x.td> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > James </x.td> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > 112 </x.td> </x.tr> <tr> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > A short story </x.td> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > Chris </x.td> <x.td border borderColor="light-blue-500" px={4} py={2} color="light-blue-600" fontWeight="medium" > 1,280 </x.td> </tr> </tbody> </x.table> </template> <x.table tableLayout="auto"> <thead> <tr> <x.th w={1 / 2}>Title</x.th> <x.th w={1 / 4}>Author</x.th> <x.th w={1 / 4}>Views</x.th> </tr> </thead> <tbody> <tr> <td>Another Story</td> <td>James</td> <td>858</td> </tr> <x.tr bg="light-blue-200"> <td> A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design </td> <td>James</td> <td>112</td> </tr> <tr> <td>A short story</td> <td>Chris</td> <td>1,280</td> </x.tr> </tbody> </x.table> </>

Responsive

To control the table layout of an element at a specific breakpoint, use responsive object notation. For example, adding the property tableLayout={{ md: "fixed" }} to an element would apply the tableLayout="fixed" utility at medium screen sizes and above.

<x.table tableLayout={{ md: 'fixed' }} />

For more information about xstyled's responsive design features, check out Responsive Design documentation.

Edit this page on GitHub