IE whitespace bug not caused by whitespace!

Arg.

I lost hair over this about a year ago, and just hacked it away. But, I want to find the real solution.

I have a dropdown menu and IE6 and 7 show some whitespace under a single item in the dropdown who also has its own sub-ul.

All the items here have Haslayout. Removing all whitespace as a test does NOT remove the space, so I’ve pretty much decided this can’t be the actual whitespace bug. That always resolves if you throw your code into one big long line.

It does go away if I comment out the sub ul though. However, changing font-size, line-height, even setting height of that sub ul to 0 does not remove the whitespace. So not sure where this space is coming from, except it is somehow caused by the sub-sub menu.

HTML4 strict, and yes, the wrapping div is holding a bg:


    <div id="menu">
      <ul>
        <li class="eerst"><a href="index.html">Home</a>
          <ul>
            <li><a href="foo.html">foo</a></li>
          </ul>
        </li>
        <li><a href="bedrijven.html">Bedrijven</a>
          <ul>
            <li class="pijl"><a href="bedrijven.html#kantoor">Kantoor</a>
           [b] <ul>
              <li><a href="bedrijven.html#intern">Intern</a></li>
              <li><a href="bedrijven.html#arch">Archief</a></li>
              </ul>[/b]
            </li>
            <li><a href="bedrijven.html#indus">Industrie</a></li>
            <li><a href="bedrijven.html#ict">ICT</a></li>
          </ul>
        </li> 
        <li><a href="foo.html">foo</a>
          <ul>
            <li><a href="foo.html">foo</a></li>
            <li><a href="foo.html#foo">foo</a></li>
            <li><a href="foo.html#foo">foo</a></li>
            <li><a href="foo.html#foo">foo</a></li>
          </ul>
        </li>
        <li><a href="foo.html">foo</a></li>
        <li><a href="foo.html">foo</a> 
          <ul>
            <li><a href="foo.html">foo</a></li>
          </ul>
        </li>
        <li><a href="foo.html">foo</a></li>
        <li class="laatst"><a href="contact.html">Contact</a>
          <ul>
            <li><a href="contact.html#tarieven">Tarieven</a></li>
            <li><a href="contact.html#offerte">Offerte</a></li>
          </ul>
        </li>
      </ul>
    </div>

CSS, included in bold is my hack for the space, so if this code is run, you do not see it:


#menu {
  position: relative;
  width: 100%; /*IE6*/
  z-index: 1000;
  background: #4f4979 url(img/menubalk.gif) 0 0;
  border-bottom: 1px solid #000;
}
	#menu ul {
	  width: 50.5em; /*smallest browser width*/
	  margin: 0 auto;
 	  min-height: 2em;
	  list-style: none;
	}

	#menu li {
	  position: relative;
	  float: left;
	  width: auto;
	  border-left: 1px solid #fff;
	}
		#menu li.huidig {
		  background-color: #160c4a;
		}
		#menu li.pijl {
		  background: url(img/menupijl.gif) 94% 15px no-repeat;
		}
			#menu li.pijl:hover {
			  background-position: 94% -18px;
			} 
[b]
		/*whitespace bug of submenu?... cause unknown*/
		* html #menu li.pijl {margin-bottom: -5px;}
	  	*+html #menu li.pijl {margin-bottom: -4px;} [/b]
		#menu li.laatst {
	  	  border-right: 1px solid #fff;
		}

	#menu a {
	  display: block;
	  padding: 0 1em;
	  color: #fff;
	  font: bold 1em/2em optima, "gill sans", "trebuchet ms", helvetica, sans-serif;
	  text-decoration: none;
	  text-align: center;
	}
	#menu li.eerst a {
	  padding: 0 1.5em; /*"home" not wide enough for submenus*/
	}

#menu ul ul {
  position: absolute;
  left: 0;
  top: 2em;
  width: 100%; /*width of parent li's, limits width*/
  background: transparent url(img/menubg.png);
  border: 1px solid #000;
}

/*Ie6 moet een explicit breede hebben*/
* html #menu ul ul {width: 8em;}
* html #menu ul li.eerst ul, * html #menu ul li.laatst ul {width: 7em;}

	#menu ul ul li { 
	  float: none;
	  width: 100%;/*IE6*/
	  border: 0;  
	}
		  
	#menu ul ul a, #menu li.eerst ul a {
	  width: 100%; /*IE6*/
	  padding: 0;
	  font-size: .8em;
	  line-height: 3em;
	  font-weight: bold;
	  text-align: center; /*IE*/
	  background: transparent url(img/menubg.png);
	}

	#menu ul ul ul {
	  left: 6.3em;
	  top: .5em;
	}
	* html #menu ul ul ul {left: 7.4em;}

		#menu ul ul ul a {
		  line-height: 2.5em;
		}

	#menu ul ul, #menu ul li:hover ul ul { 
	  margin-left: -9999px; 
	}


/*IE7 trigger, may not need it here*/
#menu li:hover {
  visibility: visible;
}
	#menu>ul>li a:focus, #menu :hover>a {
	  background-color: #160c4a;
	}

	#menu ul ul a:focus, #menu ul ul a:hover, #menu li.eerst>ul a:hover {
	  color: #000;
	  background: transparent url(img/menubg2.png);
	  outline: 0;
	}
	* html #menu ul ul a:hover {
	  color: #fff; 
	  background-color: #160c4a; 
	  background-image: none;
	}
 
	#menu a:focus+ul, #menu li:hover>ul, #menu ul ul ul {
	  margin-left: -1px;
	}
	* html #menu li:hover ul, * html #menu ul ul li:hover ul {margin-left: auto;} /*csshover.htc*/

	#menu ul ul li:hover>ul {
  	  margin-left: 0px;
	}
	#menu ul ul a:focus { 
	  margin-left: 9999px; 
	  color: #000; 
	  background: transparent url(img/menubg2.png);
	  border: 1px solid #000;
	  outline: 0;
	}  
		#menu ul ul a:focus:hover {
		  margin-left: 0; /*ff doubles margins*/
		}
		* html #menu ul ul a:active:hover {
		  margin-left: auto;  /*also IE6*/
		}	

I’ve been looking and it seems I have haslayout, it seems it’s not whitespace, it seems not to be caused by something like font-size or line-height. I do wonder if em’s are playing a part here. This is both IE6 and IE7 doing this. IE8 and all modern browsers I’ve tested are ok.

Images!
Modern browser, in this case FF:

FF:

IE7 (with boxes highlighted using IE developer tool):

IE zoomed shot

What am I missing??

Hi Mallory,

Any chance you can throw up a live example as I can’t see the gap you are talking about when images are missing. (Or perhaps use background colours so that I can see where the gap is.)

The only 100% sure way to kill whitespace bugs is to float the elements and I always float the lists and anchors ina dropdown and never run into this issue.

e.g.


#menu ul ul li,#menu ul ul li a{float:left;clear:left}

Of course I can’t check if that is a fix for you though :slight_smile:

I suspect that the problem is the anonymous block box bug that I keep harping on about (but no one listens :)).

In a drop down menu the inline element runs straight into a block element and therefore the browsers needs to construct an anonymous block box on the fly to make up for the one that you missed.

Semantically the anchor should be in a block tag (and possible a heading tag at that).
e.g.


<li>[B]<p><a href="bedrijven.html">Bedrijven</a></p>[/B]
            <ul>
                <li class="pijl">[B]<p><a href="bedrijven.html#kantoor">Kantoor</a></p>[/B]
                    <ul>
                        <li><a href="bedrijven.html#intern">Intern</a></li>
                        <li><a href="bedrijven.html#arch">Archief</a></li>
                    </ul>
                </li>
                <li><a href="bedrijven.html#indus">Industrie</a></li>
                <li><a href="bedrijven.html#ict">ICT</a></li>
            </ul>
        </li>

However none of that may apply to your layout as I can’t see the gap even though I’ve added background colours so I must have put background in the wrong place.

Arg, I was planning as I wrote the above to change every instance of menu.png to dark blue and menubg2.png to light grey.

The anchors are set to display: block which has always fixed the inline-next-to-a-block problem in IE before, and it’s not happening to the first-level menu.

However, there is a live site, which is my dev version. Thanks.

Ah, and there is only one place with this bug. It’s only under bedrijven as shown in my screenshots. It’s a single place, and again you won’t see it if you completely copy my code because of the dirty hack I have in there (it works, but… it’s a dirty hack. I no likeses the hax).

Hi,

Just checked that page and the fix I offered first cures it straight away.:slight_smile:


#menu ul ul li,#menu ul ul li a{float:left;clear:left}

As I said I always use that method because it seems to be the only fullproof way to beat this whitespace bug. Haslayout or display:block bock are not full-proof but floating cures the problem in 100% of cases.

Hi,

Just checked that page and the fix I offered first cures it straight away.:slight_smile:


#menu ul ul li,#menu ul ul li a{float:left;clear:left}

As I said I always use that method because it seems to be the only fullproof way to beat this whitespace bug. Haslayout or display:block bock are not full-proof but floating cures the problem in 100% of cases.

  1. you are using sibling selectors for no good reason, good luck with that cross browser.

  2. there is NOTHING on this menu that should be warranting the use of * html hacks.

  3. margin for positioning sub-menu items in my experience is a steaming pile of /FAIL/. Absolute position those buggers.

  4. you CANNOT trust %/em for width on a absolute positioned element when you are planning on positioning it’s children off of it thanks to FF being a bit silly about how it rounds things off compared to other browsers.

Basically, IMHO you’ve got this two or three times more complex than need be.

Gimme a few minutes, I’ll belt out a PROPER CSS for what you are trying to do.

It did turn out very complex, partially because I wanted this keyboardable. Without JS.

  1. you are using sibling selectors for no good reason, good luck with that cross browser.

Do you mean +? + works with a keyboard. If you know another way to get the next sibling to appear when its prevSibling is focussed, then thank you.

Absolute position those buggers.

They are. But I’m changing the margins rather than the positions.

  1. there is NOTHING on this menu that should be warranting the use of * html hacks.

I’d LOOOOVE to get rid of those.

  • was hitting the IE6 bug where abso-po’d children wouldn’t base their width off the parents (main-level li’s). That’s mostly the source of the rest of them, though others are because
  • I’m not letting IE6 touch my bloated semi-transparent PNGs : ) so IE6 just gets whole differnent colours etc
  • and this one is because I chose Peterned:
    • html #menu li:hover ul, * html #menu ul ul li:hover ul {margin-left: auto;} /csshover.htc/

0 did not work, although I wondered if that was due to margin rather than left.

  • aaand this one was because IE6 does what FF does:
    #menu ul ul a:focus:hover {
    margin-left: 0; /stopt rare Gecko issue! Doubling linker marges/
    }
    * html #menu ul ul a:active:hover {
    margin-left: auto; /ook IE6 issue/
    }
    Try hovering over an item but then also clicking it, without that code, in either IE6 or FF. All other browsers are fine, but ffux and IE6 will count the :hover + the :focus to get your a bazillion pixels too far to the right.

And it must be pixels, though I suspect you’re going to do it in pixels anyway. I would like to know why :focus doesn’t work on em’s.

  1. you CANNOT trust %/em for width on a absolute positioned element when you are planning on positioning it’s children off of it thanks to FF being a bit silly about how it rounds things off compared to other browsers.

I don’t mind the ffux being a little off, but I figured that I did NOT want px width (even though, yes, my container is ultimately in px). Is it terrible in your foxes? Both of mine (linux and windows) are ok.

You can can solve the double margin bug by adding display inline:


.whatever {
  float: left;
  margin-left: 10px;
  display: inline;
}

Even though it says display inline it’s still a block element (because of the float left I believe). Works cross-browser.

I don’t have the double margin bug.

Oh, I thought


#menu ul ul a:focus:hover {
	margin-left: 0; /*ff doubles margins*/
}

referred to the double margin bug. Never mind.

That’s a firefox “bug”, though possibly it isn’t a bug, but doesn’t do what all other browsers do. :hover + :focus is being added together in Firefox. :hover + :active are being added together in IE6.

I’m very much looking forward to DrHouse getting me some cleaner code. I’m not entirely happy with it (but then, that can go for the whole site, which really, really needed a designer).

No, it gives all sub anchors the gap, instead of just the one with its own dropdown (in IE7). Sorry I didn’t get back to this, only just back to my menu today.
I tried just making all anchors float: left separately, where I have #menu a {display: block;} but, no guitar.

Hi Mallory,

I must be looking at something different because the page looks identical in Firefox and IE7 with my fix added (floating all anchors and list elements in that structure) and your negative margin hacks removed (which by the way you are giving to all browsers and not just ie6 as you missed out the universal selector).

See attachment.

(which by the way you are giving to all browsers and not just ie6 as you missed out the universal selector).

No, it’s there (see above):


		/*whitespace bug of submenu?... cause unknown*/
		* html #menu li.pijl {margin-bottom: -5px;}
	  	*+html #menu li.pijl {margin-bottom: -4px;} 

However in my live dev version, when I commented them out, I simply threw a slash in front of the IE6 line, like so:


		/* html #menu li.pijl {margin-bottom: -5px;}
	  	*+html #menu li.pijl {margin-bottom: -4px;} */

cause I’m lazy that way : ) I might have had a moment where the whole /* was gone when uncommenting them during testing, but not when I had the hacks in place originally (before posting here).

I tried the floats two ways:
First I tried adding it to my anchors in the #menu a section, replacing display: block. When that made the spaces in IE7 I removed that and just plugged your code in.

My mistake was forgetting that I had unfloated the sub li’s, and that came after where I put your code. So my end result was my a’s floated but my sub li’s not. This gave all sub anchors (or more likely, sub li’s) the gap underneath, in IE 6 and 7.

However, when everyone is floated, IE6 does not show the subs. I’ve even uncommented the whole margin-left: -9999px line, and every browser shows all the subs (except one I’ve commented out. I’ll eventually figure that one out, though.

That’s just the usual IE6 bug with floats and absolute elements in the same context. You just need this nonsense fix plus the fix for the stacking problem in IE6.


* html #menu ul ul li:hover ul{clear:both}
* html #menu ul ul li:hover{z-index:999}


Working fine locally :slight_smile:

Seems working here as well.
Thank you.