CSS Tables
CSS Tables
Table Width and Height
Horizontal Alignment
The text-align property sets the horizontal alignment (like left, right, or center) of the content in <th> or <td>.
By default, the content of <th> elements are center-aligned and the content of <td> elements are left-aligned.
Vertical Alignment
<pre><code>//the following example sets the vertical text alignment to bottom for <td> elements
td {
height: 50px;
vertical-align: bottom;
}</code></pre> The vertical-align property sets the vertical alignment (like top, bottom, or middle) of the content in <th> or <td>.
By default, the vertical alignment of the content in a table is middle (for both <th> and <td> elements).
Table Padding
To control the space between the border and the content in a table, use the padding property on <td> and <th> elements.
Horizontal Dividers
Hoverable Table
Striped Tables
For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd) table rows.
Table Color
Responsive Table
<pre><code><div style="overflow-x:auto;">
<table>
... table content ...
</table>
</div></code></pre> A responsive table will display a horizontal scroll bar if the screen is too small to display the full content.
Add a container element (like <div>) with overflow-x:auto around the <table> element to make it responsive.
Related concepts
- CSS Tables: Table Width and Height
- CSS Tables: Horizontal Alignment
- CSS Tables: Vertical Alignment
- CSS Tables: Table Padding
- CSS Tables: Horizontal Dividers
- CSS Tables: Hoverable Table
- CSS Tables: Striped Tables
- CSS Tables: Table Color
- CSS Tables: Responsive Table
- Table Borders
- Collapse Table Borders
Semantic portal