IE7 cause of "Text - Empty Text Node"

Jeremy picture Jeremy · Sep 4, 2009 · Viewed 18.4k times · Source

I'm using the IE web developer toolbar to troubleshoot an issue. A blank white space is appearing below a list item, and I can't logically figure out why. Using the web dev toolbar, I see that in example 1 below, a "Text - Empty Text Node" is being output below "Text - Google". Ironically, in the second, with a space manually inserted after the word "Google", that text node no longer appears. It would make complete sense to me if the results were reversed. Any ideas what may cause this odd behavior?

Note: this is occuring in IE7, but not IE8.

<li><a href="www.google.com">Google</a></li> - empty text node appears at end

<li><a href="www.google.com">Google </a></li> - no empty text node

Update: Ok I've narrowed down this issue. Basically, it seems like there's a conflict between some of the attributes I'm using. I need the a tags to be display as block, so they will wrap correctly when there are multiple lines. But I also need no empty space in between the items. I'm not quite sure why that empty space solves the problem, and would prefer not to just "hack" it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
a
{
    display:block;
}
li
{
    zoom: 1;
}
</style>
    </head>
<body>
    <ul>
        <li>
        <div style="background-color:blue">
            <a href="#"><img  src="http://www.google.com/intl/en_ALL/images/logo.gif"/></a>
        </div>
            <ul>
                <li style="background-color:Red"><a href="#">One</a></li>
                <li style="background-color:green"><a href="#">Two </a></li>
                <li style="background-color:Yellow"><a href="#">Three</a></li>
            </ul>
        </li>
    </ul>
</body>
</html>

Answer

Emily picture Emily · Sep 4, 2009

Now that the <a> is a block level element, you have to give it hasLayout too.

a
{
    display:block;
    zoom:1;
}