Make columns of equal width in <table>

HtmlCss

Html Problem Overview


How do I make columns of equal width in <table>?

I am dynamically changing the number of columns. Today I have 13 columns. Tomorrow it will be raised to 16. I do not particularly want to recalculate.

Html Solutions


Solution 1 - Html

I think that this will do the trick:

table{
    table-layout: fixed;
    width: 300px;
}

Solution 2 - Html

Use following property same as table and its fully dynamic:

ul {
    width: 100%;
    display: table;
    table-layout: fixed; /* optional, for equal spacing */
    border-collapse: collapse;
}
li {
    display: table-cell;
    text-align: center;
    border: 1px solid pink;
    vertical-align: middle;
}

<ul>
  <li>foo<br>foo</li>
  <li>barbarbarbarbar</li>
  <li>baz klxjgkldjklg </li>
  <li>baz</li>
  <li>baz lds.jklklds</li>
</ul>

May be its solve your issue.

Solution 3 - Html

Found this on https://stackoverflow.com/questions/570154/html-table-keep-the-same-width-for-columns

> If you set the style table-layout: fixed; on your table, you can > override the browser's automatic column resizing. The browser will > then set column widths based on the width of cells in the first row of > the table. Change your to and remove the inside > of it, and then set fixed widths for the cells in .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael PhelpsView Question on Stackoverflow
Solution 1 - HtmlAdamLView Answer on Stackoverflow
Solution 2 - HtmlDivya BhaloidiyaView Answer on Stackoverflow
Solution 3 - HtmlNitin VarpeView Answer on Stackoverflow