tags:

views:

269

answers:

3

Hi, I have two tables side by side. I need the rows to line up, but sometimes the content can be longer than the table row due to width constrictions on the page and it breaks and makes a two line table row.

Is it possible to make something like double rows that can hold two lines of text so everything lines up no matter if the content is 1 or 2 lines?

Thanks

A: 

You could add a (minimum) height to the table rows or cells (though it won't work in old browsers like IE6) with something like:

tr {
   min-height: 2em;
}

or

tr {
   min-height: 24px;
}

If you need it to work the same in IE6, you can add 'height: ...' instead.

Hope this helps!

ylebre
You can use the min-height fast hack to get around the IE6 issue: http://www.dustindiaz.com/min-height-fast-hack/
Mark Hurd
-1, because if at some point you end up with 3 lines, it will break again. Using one large table as suggested in another answer is more reliable.
molf
The request was specific for two lines - I fail to see how 'overflow hidden' is a better solution since it will hide the text, breaking it in a worse way for the user. Also, I try to keep the structure of the html the same because it isn't always so easy to change it. It might be 'better', but can't always be done. I believe this solution is less intrusive.
ylebre
A: 

Give the TD height:2.5em or so (You will have to play with this value, depends on other params like the margins/paddings/line-height you use.

Itay Moav
+1  A: 

You could solve this 2 ways, one would be to create rows with a fixed height like you propose, the other solution would be to create a big table with 3 columns where you remove the borders from the middle column so it looks like 2 tables.

The solution you were asking for could be as follows:

<style>
td { vertical-align: top; }
td div { height: 40px; overflow: hidden; }
</style>
<table width="400">
  <tr>
    <td><div>short content</div></td>
    <td><div>long content long content long content long content</div></td>
    <td><div>long content long content long content long content</div></td>
  </tr>
  <tr>
    <td><div>long content long content long content long content</div></td>
    <td><div>short content</div></td>
    <td><div>long content long content long content long content</div></td>
  </tr>
</table>
Michiel
+1, using one large table that combines both smaller tables is the most reliable approach.
molf