category | created | tags | title |
---|---|---|---|
Tip |
2021-03-02 |
CSS |
Make a table with equal column widths |
Setting the width for each cell explicitly is the straightforward way to give all columns the same width. For example, the CSS declaration below splits a table of four columns into parts whose widths are the same:
table td {
width: 25%;
}
However, the approach doesn't work if the table has a dynamic number of columns. Fortunately, we can use the table-layout
property to do that.
No matter what how many columns the table has, they will have the same widths.
table {
table-layout: fixed;
}