Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Td height on two separate tables

I have two separate tables on which I use a focus+hover function on each tr that works great on both tables simultaneous, my problem is with td height because if the description of a td from fist table is greater will be displayed on two rows in the same td and the height of td will be modified but only into first table td. How is possible to remember the height to the td from first table and to add that on td from second table in order to have both td same size. In my example only first two tr are displayed ok the other two are displayed not ok because of description of first table td.

fiddle example: http://jsfiddle.net/Ksb2W/45/

   for bounty  please check this example to see the difference on chrome and ie8:

http://mainpage.ueuo.com/

Thank you.

like image 848
mcmwhfy Avatar asked Apr 27 '12 13:04

mcmwhfy


People also ask

How do you make two tables the same height?

To get the widths that you need, simply set the width of one of the . cell-wrap elements to some value, for example, 70% on the left . cell-wrap . You then set the height of the nested tables to 100% and the two tables will scale to the same height.

Is it allowed to use different row heights in HTML?

HTML tables can have different sizes for each column, row or the entire table. Use the style attribute with the width or height properties to specify the size of a table, row or column.

How do you set height in TD?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.

How do you fix the height of a row in a table?

The height of rows 'tr' in a table can be fixed very easily. This can be done by adding the height attribute in the tr tag. If the height is not specified, the height of the row changes according to the content. The height can be specified either in pixels, or percentage.


2 Answers

If I've understood you correctly you want the heights within each row of both tables to be the same?

If so, this should work:

$("table:first tr").each(function(i) {
    $("table:last tr").eq(i).height($(this).height());
});

Obviously the use of :first and :last selectors is not ideal, you should amend those to be id selectors.

Example fiddle


UPDATE

The solution to the problem you've mentioned in your bounty is because of the border on the td elements not being accounted for.

Replace height() with outerHeight() when checking the current row and it should work fine:

$("table:first tr").each(function(i) {
    $("table:last tr").eq(i).height($(this).outerHeight());
});
like image 179
Rory McCrossan Avatar answered Oct 03 '22 10:10

Rory McCrossan


Get the max height of all the tr elements and then set the height of all the trs to this height :

// get all heights
var heights = rows.map(function () {
    return $(this).height();
}).get();

// use max to get the max !
var maxHeight = Math.max.apply(null, heights);

// set the height
rows.height(maxHeight);

Working Example

(I think I may have mis-understood your question ... this will set the height of all the trs to the same height)

like image 40
Manse Avatar answered Oct 03 '22 10:10

Manse