Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a 100% width table with the columns all equal width?

Tags:

html

css

I'm trying to make a table that stretches 100% of the page (or whatever container it's in, depending on where I use it).

When I specify the width of the table to 100%, it automatically resizes the columns based on the width of their content. This is nice most of the time when I wouldn't mind different width columns, but for this, I need all of the columns to be the same width. I know that I could specify a percentage width for the columns, but I need this to work for any number of columns.

Here's my code so far: http://jsfiddle.net/zwWHZ/2/

Is it possible to have a table with a width of 100% and equal column widths without having to specify the percent for each column with pure CSS?

like image 431
Zak Avatar asked Feb 20 '11 04:02

Zak


People also ask

How do I make columns equal width?

Select the column or columns that you want to change. On the Home tab, in the Cells group, click Format. Under Cell Size, click AutoFit Column Width. Note: To quickly autofit all columns on the worksheet, click the Select All button, and then double-click any boundary between two column headings.

How do you give equal width to all TD tables?

Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.

How do I equally space columns in HTML table?

The CSS to make all the columns equal in width is as follows. The table-layout: fixed; rule specifies that the table is to take its dimensions from the <table> element's width and the width of the first row of cells (or the <col> elements, if you have them).


1 Answers

I tried putting table-layout: fixed; into the table section of the CSS, and that appeared to work (even when I changed the number of columns). The source where I found that is here.

like image 114
Jeremiah Willcock Avatar answered Sep 19 '22 14:09

Jeremiah Willcock