HTML table: keep the same width for columns

I have a table with several groups of columns. The table is larger than my page, so I have a control to show/hide some of these groups to fit on the page. The initial table looks good: all columns are about the same width within a group. But when I hide a group, the columns are not the same width anymore, and it looks bad.

Example: http://www.reviews-web-hosting.com/companies/apollohosting.html (broken link)

So far, the table looks fine. Click on >>. The first column under "Ecommerce Pro" is much wider than the other columns under "Ecommerce Pro", it looks odd. Click on <<, this time the first column under "Value" is too wide. At least on Firefox.

I've tried to use

<colgroup><col /><col span="5" />...

but no luck. If I set a col to style="display: none", the set of columns is still displayed.

Any HTML/CSS tip to keep the columns with the same width withing a group?

Edit:

  • to hide a column, I have to use visibility: collapse
  • it seems to be resizing well now, I do not know why

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 <thead> to <caption> and remove the <td> inside of it, and then set fixed widths for the cells in <tbody>.


give this style to td: width: 1%;