IE8 Stretch Table Cell Height

I have a spreadsheet based page layout, and as far as I would like to restructure it with more modern markup, this is not an option. The layout uses a cell that includes two lines as a sidebar on the right side, and the upper left cell contains a simple heading, and the lower left cell contains the main content of the page. The upper left cell has a fixed height, and the height of the lower cell and the right cell is not specified. I created a simplified example to illustrate my problem:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style type="text/css"> .fixed { height: 100px; } table { border: 1px solid #000; } td { border: 1px solid #ddd; vertical-align: top; } tr { border: 1px solid #cfc; } * { padding: 15px; } </style> </head> <body> <table> <tr class="fixed"> <td>left</td><td rowspan="2"><div style="height: 500px;">right</div></td> </tr> <tr class="stretch"> <td>left</td> </tr> <tr class="footer"> <td colspan="2">footer</td> </tr> </table> </body> </html> 

I set the height of the right column in the row to 500px to simulate content that is higher than the height of the two left columns. This behaves as expected in modern browsers: the height of the upper left cell remains fixed, and the lower cell stretches to fill additional space. But in IE8, both left cells are stretched vertically. I need a top cell to keep its fixed height. How to get IE8 to estimate the height specified for the top left cell using only CSS?

Edit: Instead of setting the height in the right column of td, I set the height in the div inside the right column.

+7
source share
3 answers

I think Jeroen is right that there are no pure CSS solutions for this problem. Each time there are cells in a table with rowspan , IE ignores any explicit heights set on these rows. The solution is to never use rowspan . In my situation, I was able to get around the problem by placing content that spanned two lines in the second line, leaving the cell in the first line empty and using negative margin to move the beginning of the content up to the first line.Hope this helps someone else. If anyone has a pure CSS solution, I will agree with that in return.

+4
source

An interesting problem. I'm afraid the answer may be that there are no real solutions to the problem you are describing, only workarounds. I found that adding some style to the second β€œleft” etc. made the problem go away, at least in your example:

 <td style="min-height: 500px;">left</td> 

Hope this helps.

PS. IE9 had the same problem.

+2
source

Even if the cell contains only the image, you should know that the cells in the table have a height calculated in accordance with the position of the baseline of the text; and the current text style affects the calculation of this base position and the spacing between lines after it. You might think that setting β€œline-height: 1” would be enough to avoid this spacing between the lines, that is, the margin difference that always occurs below each line of text. This is not enough. The easiest solution is to set the β€œ line-height: 0.8 ” (or lower) for the cell containing the image, so that the default added 0.2% gap is below the baseline (which is still considered the default by default to the absence of text) will make the baseline suitable for cell height. Then you can correctly place the image (or any element of a fixed height) in a cell whose height will determine the height of the cell, without increasing the height of the cell.

Note: with this height line, any text that you placed in this cell will have a baseline only at the bottom of the cell, so the descriptors will overlap the bottom pad, border, border between the current cell, or on the border, indentation or contents of the cell in the next row or contents below the table if the cell was in the last row.

Tested in Google Chrome (current version 15)

Example (HTML5):

 <!DOCTYPE html> <html><head> <title>Examples of image transforms (rotations and mirroring)</title> <style> table,tbody,tr,td,image{margin:0;border:1px solid #999;border-collapse:collapse;border-spacing:0;background:#FFF;color:#000;padding:0;vertical-align:middle;text-align:center;} td.z{line-height:0;} </style> </head><body> <table border="0" cellspacing="0" cellpadding="0"> <tbody><tr> <td style="border-bottom:hidden">Normal 0Β° (1,0,0,1,0,0)</td> <td style="border-bottom:hidden">Mirrored 0Β° (-1,0,0,1,0,0)</td> <td style="border-bottom:hidden">Mirrored 90Β° (0,1,1,0,0,0)</td> <td style="border-bottom:hidden">Normal &minus;90Β° (0,1,-1,0,0,0)</td> </tr><tr> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(1,0,0,1,0,0);"/></td> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(-1,0,0,1,0,0);"/></td> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(0,1,1,0,0,0);"/></td> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(0,1,-1,0,0,0);"/></td> </tr><tr> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(1,0,0,-1,0,0);"/></td> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(-1,0,0,-1,0,0);"/></td> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(0,-1,1,0,0,0);"/></td> <td class="z"><image alt="" src="Avatar-220px.jpg" style="-webkit-transform:matrix(0,-1,-1,0,0,0);"/></td> </tr><tr> <td style="border-top:hidden">Mirrored 180Β° (1,0,0,-1,0,0)</td> <td style="border-top:hidden">Normal 180Β° (-1,0,0,-1,0,0)</td> <td style="border-top:hidden">Normal 90Β° (0,-1,1,0,0,0)</td> <td style="border-top:hidden">Mirrored &minus;90Β° (0,-1,-1,0,0,0)</td> </tr></tbody> </table> </body></html> 

Note the trick in the "z" class for table cells (line-height: 0) containing only the image so that they exactly match the size of the image. The images shown in this example are a small square photograph in 8 different orientations. There is only a thin 1px gray border covering each photo, and its label shown above or below, the photos exactly correspond to the cell borders.

Note that the reorientation uses WebKit styles (for Safari and Chrome); You can add equivalent properties for IE and Firefox by changing the prefix; CSS3 does not require a prefix. If these transformations are not supported, the images will not be reoriented / mirrored, but they will still correspond exactly to the cell without additional internal gaps.

+1
source

All Articles