Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make columns of equal width in <table>

Tags:

html

css

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.

like image 580
Michael Phelps Avatar asked Dec 04 '13 12:12

Michael Phelps


People also ask

How do I make columns the same width in a table CSS?

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 .

How do I make table columns equal width in HTML?

Just add style="table-layout: fixed ; width: 100%;" inside <table> tag and also if you do not specify any styles and add just style=" width: 100%;" inside <table> You will be able to resolve it.

How do you fix column width in a table?

The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.


2 Answers

I think that this will do the trick:

table{     table-layout: fixed;     width: 300px; } 
like image 119
AdamL Avatar answered Nov 02 '22 23:11

AdamL


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.

like image 24
Divya Bhaloidiya Avatar answered Nov 02 '22 23:11

Divya Bhaloidiya