Solved

Two tables side by side with equal height.

Posted on 2007-12-05
5
786 Views
Last Modified: 2013-11-19
Hello

I have 2 tables one on left and one on right.

I need to do something to have both tables same height. but each table have different number of rows.

I dont know which one will be heigher. Also atble on left side usualy have row height 1em and row in table on right usuale have multiple lines.

Is it posible to have both table the same height?

Best Regards
Fooky
/********************************myhtml.html*************************/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <meta name="generator" content="PSPad editor, www.pspad.com">

  <link rel="stylesheet" href="mycss.css" type="text/css">

  

  <title></title>

  </head>

  <body>
 
 

<div id="div1">
 

<table class="tab1">

  <tr>

    <td colspan="6"> Table 1 - Left </td>

  </tr>

  <tr>

    <th>

      header

    </th>

    <th>

      header

    </th>

    <th>

      header

    </th>

    <th>

      header

    </th>

    <th>

      header

    </th>

    <th>

      header

    </th>

  </tr>

  <tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

  </tr>

  <tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

  </tr><tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

  </tr><tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

  </tr><tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

      data

    </td>

  </tr>  

</table>
 

<table class="tab2">

  <tr>

    <td colspan="2"> Table 2 - Right </td>

  </tr>

  <tr>

    <th>

      header

    </th>

    <th>

      header

    </th>

    <th>

      header

    </th>

  </tr>

  <tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

   VERY long data : 

   Lorem ipsum dolor sit amet consectetuer porttitor Aliquam elit laoreet ac. 

   Congue tortor metus et nulla ridiculus eget et urna ut nisl. At a Integer 

   non risus Nullam nec Aliquam id convallis interdum. Turpis feugiat id pede 

   dui enim mus consequat elit eu hendrerit. Nibh sem semper odio lacus vitae 

   accumsan et justo vel id. Vestibulum purus orci Vivamus quis nonummy 

   consectetuer Morbi amet.

 </td>

  </tr>

  <tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

   VERY long data : 

   Lorem ipsum dolor sit amet consectetuer porttitor Aliquam elit laoreet ac. 

   Congue tortor metus et nulla ridiculus eget et urna ut nisl. At a Integer 

   non risus Nullam nec Aliquam id convallis interdum. Turpis feugiat id pede 

   dui enim mus consequat elit eu hendrerit. Nibh sem semper odio lacus vitae 

   accumsan et justo vel id. Vestibulum purus orci Vivamus quis nonummy 

   consectetuer Morbi amet.

 </td>

  </tr>

  <tr>

    <td>

      data

    </td>

    <td>

      data

    </td>

    <td>

   VERY long data : 

   Lorem ipsum dolor sit amet consectetuer porttitor Aliquam elit laoreet ac. 

   Congue tortor metus et nulla ridiculus eget et urna ut nisl. At a Integer 

   non risus Nullam nec Aliquam id convallis interdum. Turpis feugiat id pede 

   dui enim mus consequat elit eu hendrerit. Nibh sem semper odio lacus vitae 

   accumsan et justo vel id. Vestibulum purus orci Vivamus quis nonummy 

   consectetuer Morbi amet.

 </td>

  </tr>

  </table>

</div>

<div style="clear:both;" />
 

  </body>

</html>
 

/********************************myhtml.html*************************/

/********************************mycss.css*************************/

#div1{

}
 

.tab1{

  float: left;

  border: 1px yellow solid;

  margin-right: 10px;

  width: 30%;

}
 

.tab2{

  float: right;

  border: 1px pink solid;

  margin-right: 10px;

  width: 66%;

}
 

td{

  border: 1px black dashed;

}
 

/********************************mycss.css*************************/

Open in new window

0
Comment
Question by:f_o_o_k_y
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 20413793
Yes it is possible. But you can't just set the height of each table to 100%. First of all you have to go a bit lower level, and set "body" and "html" to height:100%, so both base containers for the page occupy 100% of the viewport. Then you can create class called fullHeight or whatever and set height to 100%. Apply this class to each table. You can see an example of this here: http://www.goofydawg.net/tblHeight/. The source code is as follows:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

 "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<title>Page title</title>

<style type="text/css">

html,body {margin:0;padding:0;height:100%;border:0;}

#contDiv {height:500px;}

#tbl1 {width:300px;float:left;border:1px solid blue;}

#tbl2 {width:300px;margin-left:1em;border:1px solid blue;}

.fullHeight {height:100%}

.clr {clear:both;height:1px;margin-top:-1px;overflow:hidden;font-size:1px;}

</style>
 

</head>

<body>
 

<div id="contDiv" class="fullHeight">

  <table id="tbl1" class="fullHeight">

    <tr><td>Row</td></tr>
 

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

  </table>

  <table id="tbl2" class="fullHeight">

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>
 

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

  </table>

</div>
 
 

</body>

</html>

Open in new window

0
 
LVL 11

Author Comment

by:f_o_o_k_y
ID: 20415533
Ok. I understand.
But I dont know how height should be #contDiv.
Its not working if for  tbl2 is heigher than #contDiv

This is an example when its not working.
Best Regards
FooKy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

 "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<title>Page title</title>

<style type="text/css">

html,body {margin:0;padding:0;height:100%;border:0;}

#contDiv {height:300px;}

#tbl1 {width:300px;float:left;border:1px solid blue;}

#tbl2 {width:300px; margin-left:1em;border:1px solid blue;}

.fullHeight {height:100%}

.clr {clear:both;height:1px;margin-top:-1px;overflow:hidden;font-size:1px;}

</style>

 

</head>

<body>

 

<div id="contDiv" >

  <table id="tbl1" class="fullHeight">

    <tr><td>Row</td></tr>

 

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

  </table>

  <table id="tbl2" class="fullHeight">

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

    <tr><td>Row</td></tr>

 

    <tr><td> VERY long data : 

   Lorem ipsum dolor sit amet consectetuer porttitor Aliquam elit laoreet ac. 

   Congue tortor metus et nulla ridiculus eget et urna ut nisl. At a Integer 

   non risus Nullam nec Aliquam id convallis interdum. Turpis feugiat id pede 

   dui enim mus consequat elit eu hendrerit. Nibh sem semper odio lacus vitae 

   accumsan et justo vel id. Vestibulum purus orci Vivamus quis nonummy 

   consectetuer Morbi amet.

</td></tr>

    <tr><td> VERY long data : 

   Lorem ipsum dolor sit amet consectetuer porttitor Aliquam elit laoreet ac. 

   Congue tortor metus et nulla ridiculus eget et urna ut nisl. At a Integer 

   non risus Nullam nec Aliquam id convallis interdum. Turpis feugiat id pede 

   dui enim mus consequat elit eu hendrerit. Nibh sem semper odio lacus vitae 

   accumsan et justo vel id. Vestibulum purus orci Vivamus quis nonummy 

   consectetuer Morbi amet.

</td></tr>

    <tr><td> VERY long data : 

   Lorem ipsum dolor sit amet consectetuer porttitor Aliquam elit laoreet ac. 

   Congue tortor metus et nulla ridiculus eget et urna ut nisl. At a Integer 

   non risus Nullam nec Aliquam id convallis interdum. Turpis feugiat id pede 

   dui enim mus consequat elit eu hendrerit. Nibh sem semper odio lacus vitae 

   accumsan et justo vel id. Vestibulum purus orci Vivamus quis nonummy 

   consectetuer Morbi amet.

</td></tr>

  </table>

</div>

 

 

</body>

</html>

Open in new window

0
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 20415706
Right, because the container div is a fixed height. I only wrapped the two tables with a container to demonstrate that if you set body and html to 100%, then set 100% to the tables, the tables will fill the vertical height of their container. In this case, it's #contDiv, but you could use pretty much any container. I just happened to use a fixed-height container for demonstration purposes only.

However, if you happen to run into this situation where one of your contained tables exceeds the size of your container, you'll have to make adjustments to the container's height either via JavaScript, or size the container to a percentage height.

0
 
LVL 11

Author Comment

by:f_o_o_k_y
ID: 20417789
In my situation its posible that bothe table will be heigher than 100%.
100% (its height of screen? am I wright?)
Also under this table there will be 3rd table and all this will be in one container.

I was also trying to use table as a container but also could not make smaller table to be larger than 100%.

So I asume I need to use javascript and set smaller table height of the bigger one.
Any other option?
0
 
LVL 12

Accepted Solution

by:
GoofyDawg earned 500 total points
ID: 20417802
Yeah... your route will probably be javascript. Use the offsetHeight of each table, then, then set the smaller's height to the offsetHeight of the larger. That should do the trick.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now