Scrollbar not appearing in IE7 when CSS overflow auto is set

Recently when working on a JQuery based UI, I encountered an annoying IE 7 problem. I had a scrollable DIV setup with overflow:auto; configured in CSS. The scrollable DIV had a one child div which contained text. As the text grows in length the parent scrollable div should trigger a vertical scrollbar. This worked fine in every browser, FF, SF, IE6/8 but would not work in IE7. When you first viewed the page in IE7 the text would just cut off and the scrollbar would not be visible, however when you clicked on another page element and brought focus back to the scrollable div, the scrollbar would then appear as expected. Annoying indeed. To fix this in IE7 I simply did the following in JQuery to dynamically adjust the height when the after the DIV gained focus and it fixed the problem. Might it help you? Who knows but it worked for me.

var h = $("myScrollingDivWithOverflowAUTOset").height();
$("myScrollingDivWithOverflowAUTOset").height(h+1);
$("myScrollingDivWithOverflowAUTOset").height(h-1);

About these ads

One Comment

  1. Posted December 14, 2010 at 7:26 am | Permalink | Reply

    You really should re-use and chain the jQuery object rather than creating a new instance repeatedly, it’ll be far more efficient. Also I’m not sure you want h-1 do you? You’re effectively shortening the div by 1 pixel since you don’t reassign h after h+1.

    var scrollDiv = $(“myScrollingDivWithOverflowAUTOset”);
    var h = scrollDiv.height();
    scrollDiv.height(h+1).height(h);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: