Home > CSS > Fix PNG transparency in IE6

Fix PNG transparency in IE6

11 October, 2008 Leave a comment Go to comments

Here’s the official link: http://www.webmonkey.com/codelibrary/Use_Transparent_PNGs_in_IE6

The problem

PNG images or icons appear with unwanted black shadows in IE6 browsers.

The fix

First of all, put the regular transparent PNG image in your HTML:

<div id="png-holder"><img src="/images/transparent.png" alt="" />

That will work perfectly in Firefox, Safari, and IE7. To make it work in IE6, add the following to your IE6 stylesheet:

#png-holder {
width: 300px;
height: 150px;
text-indent: -9999px;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader
(src='/images/transparent.png', sizingMethod='crop');
}

That filter rule is a proprietary Microsoft code that will force IE6 to render the alpha transparency in the PNG – but it does it by drawing another box on top of everything on the page and sticking the png in there, which leads to some odd behavior. Here’s the breakdown:

  • You must use the filter on a containing element for the PNG, not the image itself. For this reason, it’s easiest to wrap the image in a DIV or P tag.
  • You must declare a width and height for the container matching the width and height of the image.
  • You have to hide the original image – hence the text-indent: -9999px; rule. You can do the same thing to a transparent PNG that you’ve set as a background on a div by using background: none; instead.
  • You must use an absolute path to the image. As far as I can tell, this is just a restriction of the filter.
  • You can set sizingMethod to crop, which means if the image is larger than the dimensions of your container, the overflow will be hidden. Alternately, you can set it to scale, which will stretch the image to fit.
  • If you absolutely position the PNG over other content on your page, the user will not be able to click on any links under the image. That’s because the filter is drawing a new box on top of everything, completely overriding your z-index rules.
Advertisements
Categories: CSS Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: