IE6 Doesn’t Hide When Overflow Is Hidden

Posted on Tuesday, February 12th, 2008

A little CSS bug that affected me twice recently. I had to create a news ticker (so 1990s, but not my design) and an image slider, both which did the same thing; moving information from one side of the screen to the other. The important part was, at some point the news or the images would disappear, seemngly sliding underneath the next part of the page. Of course, this worked in all browsers but every developer’s favourite, Internet Explorer 6. Let me explain why this was happened and what I did to fix it.

The Problem: Position Relative

In order to create the effect of moving both the news ticker and the images, I set up something like the following:

<div id="slide_frame">
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
<li>Item four</li>
<li>Item five</li>
</ul>
</div>

With the following CSS:

#slide_frame { width:300px; }
#slide_frame ul {
list-style-type:none; position:relative; width:600px;
}
#slide_frame li { float:left; padding:0 5px; }

The sliding was done with JavaScript, jQuery, which I am falling in love with, as it happens, and the result was fine in all browsers but IE6 where both the news ticker and the image slider remained visible at all times.

The issue, it seems, comes down to the <ul> being positioned relatively, which had to be done, so that the JavaScript could move it about. Removing the position hid the out of shot part of the list but meant it wouldn’t move anywhere.

The Solution: Position Relative

Thankfully, this turned out to be an easy fix! In order to make IE6 behave all you need to do is apply position:relative to the containing <div> as well. Don’t go around playing with z-indexes like I did for half an hour anyway!

I have provided an example of the problem, with the fix to show what should be happening. Interesting point for those of you with many, many versions of Internet Explorer at your disposal, IE5 and 5.5 are not affected by this issue.

So, don’t get caught out by hidden overflow and relative positions again, just position your container relatively too!

If you enjoyed this post, why not subscribe to Unintentionally Blank

Comments

  1. Brandon Says:

    Thanks a ton! I constructed an image slider using Mootools and I had the same problem. Nice work. I just wish the world would come together as a whole and say that no one will use IE6 every again. It would make our jobs easier.


  2. Phil Says:

    One day Brandon, one day we won’t have to worry about that wreck of a browser.

    Glad this helped though!


  3. Xander Says:

    Thank you Phil, you helped me with solving the issue.


  4. Tim Says:

    I was having the same problem with a mootools sliding image gallery. Your fix worked great.

    Thanls


  5. Matt Says:

    Thanks heaps :-)


  6. Daniel R. Ziegler Says:

    Thank you thank you thank you so much! I have been struggling with this problem for the past week reading as much as I could about every possible quirk in IE but none solved my problem like yours. I would call you a god, but that would be blasphemy.


  7. Bas Says:

    Thanks for the solution! I had the same problem in two projects, problem solved within 10 seconds.


  8. R. Sigg Says:

    You. Are. A. Genius!

    (Down with IE6!)


  9. Mike Says:

    Thank you very much for sharing this monumental discovery.

    I have been struggling with this for … weeks.


  10. dnnsldr Says:

    Thanks for the solution. I am using the Prototype Carousel and all that was needed was the position:relative added to the .container class and everything works great in IE6 now. Thanks again for the solution.


  11. Olly Hodgson Says:

    Phil, you’re a scholar and a gentleman. I thought I’d seen everything when it came to IE6, but then today I ran headlong into this lovely bug.


  12. enkosynthesys Says:

    that was veeery helpful. spend two days alignin flash object inside a container. Thanks!


  13. Gary Says:

    Wow, thanks for this! I was doing a similar enough animation thing with an image and couldn’t get it working on IE.

    cheers :)


  14. Jeff V Says:

    Thanks. I messed around with absolute positioning last week to try to sort this exact problem. That really wasn’t satisfactory, and I had another look today. An hour later after fiddling I decided to search again, and your article reminded me how to fix this problem. Thank you very much.


  15. Dave Says:

    This has worked great for me in the past and was a quick fix to a problem that I was afraid was going to be a huge pain. Unfortunately on my latest project it didn’t do the trick. I’m doing something very similar, sliding image from right to left with jQuery, but even with the containing element set to relative the images are still visible and in the flow of the page. Any other tricks?


  16. Luis Says:

    Thanks!


  17. Darren Rees Says:

    Excellent. Thanks, I got stuck on this myself.


  18. W Bell Says:

    Well, this worked for my problem using Spry images for a gallery in a DIV. The only browser that required this fix was IE 6 on Win2000 and XP. I thought it was going to be a big problem as well so many thanks to the solution poster!


  19. Phil Says:

    6 hours on this problem. I love you.


  20. Joe Clay Says:

    I love you also. God that was a pain in the ass. I spent most of my time looking at an unrelated float problem!


  21. alice Says:

    that’s really helpful, thank you!


  22. Matt Says:

    Thanks a lot. This worked! IE6 can be so frustrating.


  23. Daniel Says:

    Thanks, you save my life ! :)


  24. johann Says:

    it’s funny how the article written two years ago still helping people :)

    thanks! ;)


  25. Andy Says:

    Wow! Thank you so much for this, glad I googled this when I did :-)


  26. stefan Says:

    Thank you! I had a similar problem today and your fixed solved it. Great find and keep up the good work!


  27. Sean Says:

    Thank you very much! Sliding comments box here with the same issue. Naturally i build in firefox because of the genius that is firebug, got it all perfect and then BAM, IE6 comes in with a wet fish round the face.

    Been googling for about 30 mins and you’ve solved the issue for me, thank you very much. All I have to do now it tweak all the alignment and I’m set.


  28. Phil Says:

    I’m really glad this is still helping out! Until IE6 finally fades away people are going to come across this problem. Thankfully, it can’t be long until the browser we all love to hate will disappear.


  29. Mike Says:

    You saved my day and night…..

    Great advice, IE6 problem solved…


  30. paul Says:

    good job on that! well played.. the position:relative was my problem on the container..


  31. marcel Says:

    thanks!


  32. Lam Says:

    My savior … Thanks a lot… 4 years guys… 4 years …


Leave a Comment