views:

64

answers:

2

Here's an odd rendering difference between IE and other browsers.

Internet Explorer 8

IE8

Firefox 3.5

FF3.5

Chrome 5

Chrome 5

See the difference? That vertical line suddenly stops in IE8. That's because IE8 refuses to display a certain background image. Here's a relevant snippet of CSS code:

td#leftbar {
    background: url(img/leftbar.gif) repeat-y right top;
    width: 100px;
}

You can get additional information by viewing the website on your own computer here: http://labs.pieterdedecker.be/vspwpg/

+3  A: 

The problem is not leftbar: It is the leftbartop table cell stretching all the way down to the bottom. That is because leftbartop is in the same table row as the content.

In fact, I think IE is the only browser doing this correctly: All elements in the tr get forced to the same height. IE is ignoring the columns' rowspan properties for some reason. Why, I do not know.

The first thing that comes to mind in terms of a solution - unless somebody comes up with an explanation for this behviour - is having a separate table on the left-hand side with the first (leftbartop) and third rows (leftbarbottom) having a fixed height.

Oh, and using tables for layout is no longer socially acceptable. Just as a side note :)

Pekka
Not sure about the height (or I'm misunderstanding). As the other TDs in the TR have a rowspan of 2, shouldn't the height of leftbartop (110) be respected?
Peter
@Peter you're right! This is odd. (And the document is valid, on top of it all....)
Pekka
@Pekka: It's not ignoring the rowspan properties. Check with the IE8 Developer Tools (F12 key should bring it up). I'm under the impression it's the height of the leftbartop that's being ignored. I'm puzzeled...
Peter
@Peter yeah, I was playing around with that. Bizarrely, if you remove the `height: 110px`, leftbartop gets *smaller* - but not small enough. I'm puzzled too!
Pekka
I didn't know that IE8 had an element inspector. Thanks for pointing that out. Weirdly, the height of `leftbartop` doesn't seem related to the height of the table row.
Pieter
Well, IE seems to not care about `#leftbar` unless it has content...If you give it content, it assigns it an arbitrary height (142 pixels in my case) and pushes it so the bottom of the cell meets the top of the third row. If you toggle `height` on `#lefbartop`, it randomly changes the height of `#leftbar` to divide the height between the two evenly (I think).
Tim Stone
Leftbar does have content, no?   counts as content. Indeed, Pekka, if you remove the height, it does get smaller. Which leads me to think it is adding the 110px to something. Yet, there's no padding or margin that could be the culprit. I'd be very interested in seeing the solution to this one!
Peter
@Peter - Oh, no, you're right. I had thought that IE was ignoring it (Developer Tools considers it an *Empty Text Node*), but now I see that I was just mistaken. Ignore my previous comment, it must be a sign that I need coffee, heh.
Tim Stone
+1  A: 

I'll second Pekka's comment about avoiding tables for layouts, but since proposing serious structural changes would be a bit extreme, the following CSS seem to work well enough to fix the problem:

TABLE#body {
  background:url(img/leftbar.gif) repeat-y 94px top;
  border-collapse:collapse;
  width:100%;
}

TD#leftbar {
  width:100px;
}

TD#leftbarbottom {
  background:#FFFFFF url(img/leftbarbottom.gif) no-repeat right top;
  height:100px;
}

As far as why there is a difference between IE and Firefox/Chrome, the only potentially relevant piece of information that I could find right now was the CSS 2.1 section on table height, which states:

CSS 2.1 does not specify how cells that span more than one row affect row height calculations except that the sum of the row heights involved must be great enough to encompass the cell spanning the rows.

So, not only is IE's behaviour bizarre, there's doesn't seem to be a clear cut explanation of what should happen. In IE's case, space required by the multi-row cells appears to be divided up using some sort of relative percentages related to the minimum height of each included row.

To illustrate this, you can cause #leftbar to take up all the space it's leaving empty now by using the following rules:

TD#leftbartop {
  height:1px;
}

TD#leftbar {
  height:150px;
}

Another interesting example is a 1/3, 2/3 split:

TD#leftbartop {
  height:33px;
}

TD#leftbar {
  height:66px;
}

Note that if you set the height to something unreasonably small (like 1px in the earlier example), it calculates a height for that cell that is not based on the relative percentage, but something else. I'm not sure where that comes from right now, but I'll play around with the numbers and see if I can take a guess at it later on.

Tim Stone
This looks good at first sight, but if you scroll to the footer you'll notice this: http://a.imageshack.us/img409/638/55427220.jpgMaybe I'm better off redoing the page layout with DIVs after all?
Pieter
@Pieter - Did you make sure to update the `background` definition in `TD#leftbarbottom`? Setting its background colour to `#FFFFFF` should hide that. As far as switching to DIVs goes, I'd certainly recommend it (if not now, sometime in the future), but IE has plenty of quirks no matter how you do things, so you'll have to decide whether or not it's worth it right now, given that you already have what you have.
Tim Stone
Whoopsie, you're right. It looks good now, thanks! I've thought about switching to DIVs entirely, but then I remembered that I chose a table layout because that vertical bar should stretch to the end of the page content. If I were to do this with two separate tables or two DIVs, there would be no easy way to size the vertical bar appropriately.
Pieter