Get IE 5.5+ to support transparent PNGs using Microsoft-chow

by Thomas Aylott Wed, 30 Nov 2005 10:18:00 GMT

Get IE 5.5+ to support transparent PNGs using Microsoft-chow -- read more

There are two ways that i use to solve the transparent PNG support issue.

Before we get into those specific methods, we have to make sure only IE is getting fed Microsoft-chow.

Read the rest of the article for the specifics.

For IE’s eyes only

Use a dedicated hacks_for_ie.css file and serve that css file via conditional comments

Example:


<!--[if IE 5]>
  <link href="/stylesheets/theme/subtletheme_IE5.css" media="screen" rel="Stylesheet" type="text/css" />
<![endif]-->
<!--[if gt IE 5]>
  <link href="/stylesheets/theme/subtletheme_IE55.css" media="screen" rel="Stylesheet" type="text/css" />
<![endif]-->

For non-tiling transparent background image PNGs

Use a proprietary Microsoft filter property

  • this method effectively replaces the use of PNGs for background images that don’t tile.
  • this method is useless against embedded img tags in the content

Example:


#search-results1 a, #search-results1 a:link, #search-results1 a:visited {
    background-image: none;
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://subtlegradient.com/images/theme/article.png', sizingMethod='crop');
}

For img tags in the content

Use a proprietary Microsoft .HTC file to dynamically adds a JS behavior to every img tag that is a PNG. It replaces the source of the items with a spacer.gif

  • This method won’t work with background for CSS background images
  • You must update your servers mime types list to serve .htc files as text/x-component .htc

Example


img {
   behavior: url("pngbehavior.htc");
}

References

For more info on conditional comments check out quirksmode.org

For more info on the wacky Microsoft-chow AlphaImageLoader and friends, check out MSDN – AlphaImageLoader Filter

For more info in the pngbehavior.htc method, or to download the pngbehavior.htc file, check out Improved PNG Behavior or the original WebFX PNG Behavior

PNG_transparency_demonstration_1.png Image taken from wikipedia

RSS feed for this post |Trackback from your site |Add your comment

  1. Note: I’m not using the pngbehavior.htc trick in any of subtlegradient’s themes for the contest

    Therefore, the example PNG used in this article won’t work right in IE on this page.

  2. Is there any way to get repeating background png’s that you know of?

    Jamie Hill about 3 hours
  3. There is no way that I know of. You can use

    1. Crop
    2. Scale &
    3. Image

    Crop will keep the image the size & shape as the pixels and cut off the edges of anything that doesn’t fit the box. Just like doing a background-image with no-tiling top left.

    Scale resizes the image to the size of the box, disproportionately. This is really handy if you just want to do like i’ve done here and have a 2pxl wide gradient stretch to the width of the box. But it’s dangerous because it stretches to the same height, too.

    Image resized the box to fit the image. This is the default. I’m not exactly sure what the implications of this one are, but i don’t think it’s reproducable in any other browser, so I ignore it.

    Thomas Aylott about 17 hours
  4. Ahh, yes. Image is useful for replacing images themselves. Just like you can set the size of an img tag, you can use the image mode to emulate that same effect.

    Thomas Aylott about 17 hours