Tuesday, September 12, 2006

IE CSS Rollovers - Revisited

Haven't had much to say lately, as I have been busy trying to wrap a project. However, I felt like this was worth taking some time to share it.

Basically, the IE Rollover Cache Bug came back to bite me today. Now, there are many documented solutions to avoiding that annoying flicker in IE when you change the background image of a hyperlink. My personal favorite is this one. But what about the browser activity indicators that are stopped and reset when you mouse out of the button? I see far less discussion of that issue, and know of no solution expect for the one I'm about to document.

Let me describe this in a little more detail. If you click a hyperlink that has a background image, all of Internet Explorer's browser activity indicators will be stopped and reset when you move your mouse off of that hyperlink. By 'browser activity indicators' I mean the 'spinner' (wavy window animation) in the upper right corner of the browser, as well as the status bar at the bottom of the browser (in WinXP, this is green & segmented). This gives the impression that the page load is complete when in fact it is not - the requested page will be displayed eventually. This happens regardless of whether you are changing the background-image property. If you change ANYTHING about that hyperlink (border-colors, sizes, text-decoration) the activity indicators will be interrupted. I can readily confirm this on IE 6, and I'm pretty sure it happens in IE 5.5. IE 5 seems to be immune. I hope to god it's fixed in IE 7.

Typically, this is not a problem because page loads happen pretty quickly these days. But if your link is submitting a form and the server takes some time responding, this can get to be quite a problem. Thinking the form submission has quietly failed, the user will click the button repeatedly, badgering your server with extra requests. Bad for the user, bad for you.

Onward to the solution. I was almost ready to give up and ban image rollovers entirely, when it occured to me that there was one last trick I hadn't tried yet. All you have to do is display the image using Microsoft's proprietary DirectX filters instead of the normal browser pipeline. Here's what you do:

/* Set up your rollover as normal */
a.MyButton{

background:url('Images/MyButton.gif');
}

a.MyButton:hover{
background:url('Images/MyButtonOver.gif');
}

/* Now hack for IE (using star hack for brevity here)*/

* html a.MyButton{
background:none;

filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Images/MyButton.gif',
sizingMethod='image');
position:relative;
cursor:hand;
}

* html a.MyButton:hover{
background:none;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Images/MyButtonOver.gif', sizingMethod='image');
}


That's basically it. Since the problem only occurs in IE, I'm fine with using a Microsoft proprietary solution. Now, AlphaImageLoader comes with its own set of caveats and gotchas, not the least of which is that you can't position the image at all. Sometimes I need to. As a workaround for that, I put an empty div in my hyperlink to which I apply the image instead, and then position the div with absolute positioning. Another point to be aware of is that sometimes hyperlinks will not function if they have an image applied in this way. However, position:relative should cure that.

I hope this helps some poor frustrated soul. As always, please post any questions or comments, and I'll do my best to find the answers.

Was this post helpful to you? If so, please consider making a small donation to keep this blog going.

13 Comments:

Anonymous Anonymous said...

There's a simple JS fix for this ie6 bug.

Check my blog http://misterpixel.blogspot.com/2006/08/title-well-its-done-my-ie6-background.html

and my site http://www.mister-pixel.com
for details.

1:32 PM  
Blogger tom said...

Thanks Dan, and well done!! Does your solution fix the interruption of browser activity indicators?

7:19 AM  
Anonymous Anonymous said...

Absolutely brilliant – thanks for the solution! This has been a pain on several developments I’ve done and I’ve been very frustrated by the lack of write-up about this problem…until now! Personally though, I found sizingMethod='scale' is a good one for 1px width repeating images which can be stretched to fill the element.

8:24 AM  
Blogger tom said...

Asa, thanks for pointing out sizingMethod = 'scale'. That's quite a useful twist on the technique!

8:31 AM  
Anonymous Anonymous said...

Check my site http://www.mapmyevent.com/

It uses css

6:32 PM  
Anonymous Anonymous said...

u could try this solution:
Use a div to wrap the background images like:
<div class="imgLoader"><img src="xxxx" alt="" /></div>
and put the div out of the page to make it disappeared(Do not use display:none)
.imgLoader{
position:absolute;
top:-1000px;
left:-1000px
}
I don't know if it works.

10:32 PM  
Blogger hax said...

AlphaImageLoader can cause a issue for the users who need IME (Input method editor) such as Chinese, Japanese...

12:32 AM  
Anonymous Anonymous said...

ralph lauren poloburberry polo shirtthe north face jacketcolumbia jacketspyder jacketed hardy clothing ed hardy clothesed hardy shirts ed hardy t-shirts ed hardy sunglasses ed hardy mensed hardy womens Wholesale HandbagsCheap HandbagsWomens HandbagsCheap PursesDesigner HandbagsTennis RacquetTennis Racket
cheap tennis racquet
tennis racquet discount
cheap tennis racket
discount Tennis Rackethead junior tennis racketwilson tennis racquet
wilson tennis racket
head tennis racketbabolat tennis racket

1:56 AM  
Anonymous Anonymous said...

God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades.gillette mach3 razor bladesfor men.As for ladies,gillette venus razor blades must the best gift for you in summer,gillette fusion blades are all the best choice for you.

2:59 AM  
Anonymous Anonymous said...

fantastic!God bless you!Meanwhile,you can visit my China Wholesale,we have the highest quality but the lowest price fashion products wholesale from China.Here are the most popular China Wholesale products for all of you.Also the polo clothing is a great choice for you.

3:01 AM  
Anonymous lljj said...

Men's polo shirts was the shirt of choice for diverse groups of teenagers
Brightly coloured polo shirts can make you look like a Day-glo dirigible.
Wonderful!You can find the father who desire fashionable eg,uggs fashion,you can enjoy uggs online here, intellectual polo shirt simultaneously

3:04 AM  
Anonymous lljj said...

Perfect!!You are a outstanding person!Have you ever wore chaussures puma, puma CAT,Puma shoes store gives some preview of puma speed cat,puma basket, puma speed, puma speed and other puma shoes. These puma sport items are at store recently and available for anyone.

3:07 AM  
Anonymous Anonymous said...

http://delii.blog.drecom.jp/
http://ameblo.jp/nikeairshoes
http://eretertyt.cocolog-nifty.com/blog/

7:07 AM  

Post a Comment

<< Home