views:

93

answers:

3

Hey,

So I've got a menu with a hover/selected state and it loads fine in IE6/IE7. However when I scroll down the page and put the element outside of the viewport and then back in I get a broken image! I have never seen an issue like this before. Has anyone else and can anyone suggest a solution. Below are examples of the working and broken image and the url to the live code.

alt text - Seen on load

alt text - Broken after scrolling out and into viewport

I'm using a sliding doors approach with a span inside an a and css background images

The full menu can be found @ http://bjmarine.net/samples.htm

Cheers, Denis

Solutions:

#navigation ul.primary-nav li.selected a.menu-item-hover{height:25px;}
#navigation ul.primary-nav li.top-level.selected a.menu-item-hover span{height:21px;}
* html #navigation ul.primary-nav li.residential.selected a.menu-item-hover{width:88px;white-space:nowrap;}
A: 

This sounds like the IE peekaboo bug to me - no specific advice, but a quick google should offer some ideas.

BrynJ
Thanks for the input but after reading around for a while it seems like thats not it.
Denis Hoctor
+1  A: 

Hi.

First of all, when checking for bugs like this (better yet, always!) validate your markup and CSS to be sure you're working on standard code. If not, you will have problems.

A quick check on your markup throws 23 errors! http://validator.w3.org/check?uri=http%3A%2F%2Fbjmarine.net%2Fsamples.htm&charset=%28detect+automatically%29&doctype=Inline&group=0

Granted, most of them are from the HEAD section, but there are a couple in the body - solve those, then try again.

Next: even with buggy markup, common sense tells you scrolling down and up shouldn't affect the rendering. That is a IE bug, for sure, so no question you'll have to change your code to solve it.

So:

  • You have invalid markup - don't expect quirks mode to interpret what you meant. Solve those before trying anything else (for example, UL can't be empty)

  • Older versions of IE don't like the '>' CSS selector. Get rid of it and use classes instead.

  • If you want to display something inline and with a specific height and width, use the display: inline-block rule, that's the correct option instead of just display: block.

  • You have negative margins. That's not recommended at all. You usually have much better ways to solve it.

As you can see, many things may be triggering that bug. Solve all of them (which you should do even if no bugs were present) and try again.

If you're still getting it, consider refactoring your markup - we can find workarounds many times, but sometimes we have to adapt (we just can't fix IE bugs remotely...)

Seb
+1 because there are a lot of things that are odd about the structure of the code, it's always best to try to stick to standards-compliance when you can (and you can here).
JasonWyatt
Thanks for the input and yes I know I should validate more and such but when it works in all new browsers including the still average IE8 reality checks in and I have to move on if I want to keep my job. Worrying about standards for the browsers that are least compliant does seem a little bit counter intuitive in a funny way.
Denis Hoctor
Denis, I couldn't DISagree more with you... standards should be preserved absolutely every time. That's what will ensure it'll work in new browsers, plus anyone maintaining your code (you now, others later) will find it much easier to do so. Also, just to name an example, how should `<UL></UL>` (invalid, as it has no children) be displayed? Since it's not standard, every browser will render it as it wants - being avoidable, I don't see why anyone would code out of the standards ever.
Seb
A: 

I think it has to do with a hasLayout issue.

I was able fix the behavior in IE 7 (I dont have IE 6 on my computer) by introducing a height property to the style, to force IE to acknowledge it had a layout.

#navigation ul.primary-nav > li.top-level > a.menu-item-hover:hover span, 
#navigation ul.primary-nav > li.top-level:hover > a span,
#navigation ul.primary-nav > li.top-level.selected > a span{
    color:#fff;
    display:block;
    margin:-17px 0 0;
    padding:12px 7px 10px 15px;
    height: 21px;     /* this is what I added, in global.css */
}

Unfortunately, there is still a problem in terms of vertical position once you set the height on the element. You can play around with the top property, or subtract more from the margin-top property though to fix this.

JasonWyatt
You can also usually set zoom: 1 to fix hasLayout in IE. And a lot of times I fix dumb IE issues by adding an unnecessary (for eveyrone else) position: relative;
Tom
I think I have it now. I set the height and it worked perfectly in IE7. I caused and error in IE6 because it then force a 100% width on the a. I got around this by specifing that for the lowest needed and using no-wrap for the menu items with two words!Thanks for the help! As mentioned by others it's not the best standard orientated code it the world but it works and only gets sent to users stuck with poor browsers.
Denis Hoctor