Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make 2 tables have the same column sizes

Tags:

html

css

I have 2 HTML tables that are directly on top of each other. Each table has the same number of columns, but the text they contain can differ. And each table can contain many rows. I would like for these 2 tables to have the exact same column width so that the columns always line up. I don't mind if the text within the columns wraps as much as necessary. And I cannot combine all the rows into a single table for other reasons.

Is there some way to make this happen?

Note that this solution only has to work in Firefox and the last 2 versions of IE.

like image 676
Shane Avatar asked Jul 31 '09 14:07

Shane


People also ask

How do I make two tables the same size?

Make all rows and columns the same sizeRight-click a table. Click Distribute rows or Distribute columns.


2 Answers

I suggest using percentage widths on your columns, making sure that those widths always add up to 100%.

<style type="text/css">
  table { width: 100%; }
  td.colA { width: 30%; }
  td.colB { width: 70%; }
</style>

<table>
  <tr>
   <td class="colA">Lorem ipsum</td>
   <td class="colB">Lorem ipsum</td>
  </tr>
</table>

<table>
  <tr>
   <td class="colA">Lorem ipsum</td>
   <td class="colB">Lorem ipsum</td>
  </tr>
</table>
like image 157
skybondsor Avatar answered Sep 30 '22 12:09

skybondsor


As far as I know you can't align the columns of two tables.

You can create one table and use the css to make it look like two.

<table>
  <tr> <!-- First table header --> </tr>
  <tr> <!-- First table rows... --></tr>
  <tr> <!-- First table footer... --></tr>
  <tr> <!-- Empty space between tables --> </tr>
  <tr> <!-- Second table header --> </tr>
  <tr> <!-- Second table rows... --></tr>
  <tr> <!-- Second table footer... --></tr>
</table>
like image 39
Toon Krijthe Avatar answered Sep 30 '22 12:09

Toon Krijthe