views:

1892

answers:

7

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"&gt;
<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"/&gt;&lt;/a&gt;
     </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>
+2  A: 

this may have to do with the "has layout", your zoom: 1 may work, also try one of these:

li { display: block; } li { width: auto; } li { width: 100%; }

you may have to counter act these with a display: inline, or float: left if your trying to get the list to show up as a horizontal menu.

hope that helps

SkyLar
+4  A: 

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

a
{
    display:block;
    zoom:1;
}
Emily
Thanks - still trying to grok the hasLayout issue.
Jeremy
A: 

I've seen this occur with images surrounded by empty divs as well in which this ugly "text node" was creating whitespace that pushed the div below it down.

<div class="top"></div>
<img src="image.jpg" />
<div class="bottom"></div>

The solution that worked for me was to wrap the image in a div:

<div class="top"></div>
<div><img src="image.jpg" /></div>
<div class="bottom"></div>
restlessdesign
A: 

The last solution, wrapping the IMG tag in an empty DIV worked for me.

Alex
A: 

I encountered a similar issue with an inline list that I was working on. IE7 was adding a small amount of space after each one of my list elements. I had difficulty tracking down the issue but I finally discovered that the white space in my HTML was causing the space. I removed the white space and everything was fixed. See before and after example below:

<!-- Before -->
<ul>
     <li><a href="#">My Account</a></li>
     <li><a href="#">Support</a></li>
     <li class="last"><a href="#">Logout</a></li>
</ul>

<!-- After -->
<ul>
     <li><a href="#">My Account</a></li><li><a href="#">Support</a></li><li class="last"><a href="#">Logout</a></li>
</ul>

Hope this helps out someone!

Cory
A: 

Thank you. The text node issue was on the img tag. If you give that a display:block, everything goes back to normal. That -3px is annoying as hell.

Jeremy Carlson
A: 

Working with Asp.Net I replaced the <a href=""></a> tags with the <asp:HyperLink NavigateUrl="" runat="server"></asp:HyperLink> tags and it worked.

I understand the original question is not about Asp.Net, but I stumbled across it in my own quest

keith