views:

489

answers:

3

Can someone please explain why IE7 insists on putting a space between the table and the ul in this example? It doesn't seem to happen in IE8 or FF.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<body>
    <ul style="background-color: Blue;">
        <li>
            <table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: Red">
                <tr>
                    <td>
                        <img style="display: block" src="http://www.google.com/intl/en_ALL/images/logo.gif"
                            height="25" border="0" width="150" />
                    </td>
                </tr>
            </table>
            <ul style="background-color: Green">
                <li>One</li>
                <li>Two</li>
            </ul>
        </li>
    </ul>
</body>
</html>
+3  A: 

All browsers have different default styles. Some make more sense than others. Try using a CSS Reset to level the playing field, so to speak.

geowa4
could not have said that better, +1
marcgg
I just tried this with the example above, adding the YUI reset and the space still appears.
Jeremy
the reset may not be perfect, but it does a good job.
geowa4
A: 

I've fought this problems with Internet explorer before, and this is the solution: remove the spaces between </td> and </tr> tags. This is how your html should be:

</td></tr></table>

The browser create a TextNode between </td> and </tr> and this is the additional space you see in your page.

Rodrigo
Why the downvote? :-S
Rodrigo
the rendering engine does this: s/\s+/\s/
geowa4
Yes, I know the engine do that thing, but, have you tried it?
Rodrigo
I didn't downvote you, but I just tried it, to no avail.
Jeremy
@Rodrigo. The downvote was probably because your proposed solution is irrelevant, as it makes no difference whether there's a space between the tags.
Phaze Phusion
Completely agree, that bug was solved in IE7, so this response is my biggest embarrassing failure here.
Rodrigo
+1  A: 

You need to give hasLayout to the li containing the table and ul.

  <ul style="background-color: Blue;">
    <li style="zoom:1;">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: Red">
Emily
Great article, thanks for sharing!
Jeremy