PNG hack for IE5/6

Internet Explorer 5 and 6 cannot handle transparency in PNG images. If the image is just loaded with an HTML IMG tag there are many workarounds available. For Drupal there are modules like PNG Behave and PNG Fix. Alternatively you can use the following Javascript code:

/*
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->
*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters))
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

 

If the PNG image appears stretched, then change the sizingMethod from 'scale' to 'crop'.

The problem that I was facing is that my PNG image is loaded as background of a div using CSS, and then the workarounds above would not work. I was trying to darken or lighten an image by overlaying an image with a div which has a PNG as background image. All workarounds use the propriertary AlphaImageLoader. You can use it directly in an exploder-only CSS file like this:

div {
   filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/path/to/image.png', sizingMethod='crop');
   width: 400px;
   height: 400px;
  }

This only works with fixed size elements. However if you leave out the height (auto) and put the width at a percentage, like 100%, then it works too. The sizingMethod may be set to scale to scale the image.

div {
   filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/path/to/image.png', sizingMethod='scale');
   width: 100%;
  }

The width may cause other problems in IE because of the box model bug. To workaround that, put any padding in an inner div and any borders in an outer div. Never put width together with padding or border in the same div, or IE5 and IE6 will break.

The path may be relative instead of absolute, but the current directory in IE's filter may not be what you would expect. In Drupal it appears to be Drupal's base path, so "sites/all/themes/your_theme/your_image.png" would work. If IE cannot find the image, the div will be transparent. Do not forget to set the background to "none" for IE.

Another problem arises, though: the links and input fields within the div often don't work. The solution is that the div with the filter should not have a position set, and that the links should have a position set, for example position: relative;. In other words:

div a, div form {
   position: relative;
}

silver rings

The codes look so simple but I am sure it is hard to try. silver rings

silver rings

The codes look so simple but I am sure it is hard to try. silver rings

shiprabrock

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. thebest-mattress.org

bilalkhan3831

I must say, I thought this was a pretty interesting read when it comes to this topic. Liked the material. . . . . www.whatsthebestbed.org

shiprabrock

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . . salle séminaire rennes

shiprabrock

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. Foose wheels for sale

當鋪

PNG is the simplest picture to be adjusted. 當鋪

micropigmentação capilar

Could it be applied in CodeIgniter framework? micropigmentação capilar

imranuddin

Hey – great blog, just looking around some blogs, seems a really nice platform you are using. I’m currently using WordPress for a few of my blogs but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?iq option

imranuddin

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... Mexican restaurants near me

shiprabrock

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Foose wheels for sale

imranuddin

Hey, great blog, but I don’t understand how to add your site in my rss reader. Can you Help me please? memory foam bed

shiprabrock

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. hamptonbay.com

shiprabrock

Hey – great blog, just looking around some blogs, seems a really nice platform you are using. I’m currently using WordPress for a few of my blogs but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it? hampton fans

social media marketing

These are some great tools that i definitely use for SEO work. This is a great list to use in the future.. social media marketing

Awesome

Its my great pleasure to visit your blog and to enjoy your great posts here. I like it a lot. I can feel that you paid much attention for those articles, as all of them make sense and are very useful. WhatsApp

devidmiller5060

My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more! nordictrack e 7.0

My friend mentioned to me

My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more! hotels inGuangzhou

devidmiller5060

Yes, great US Military force. Also, in his post you have given a chance to listen about US Military. I really appreciate your work. Thanks for sharing it. online denim shirts Pakistan

devidmiller5060

I read this article. I think You put a lot of effort to create this article. I appreciate your work. Network+ Salary

facebook

Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me. facebook

Awesome

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. marketing1on1.com

shiprabrock

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. memory foam bed

devidmiller5060

My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more! mexican restaurants boston

devidmiller5060

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! 中古車

devidmiller5060

My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more! plumber

shiprabrock

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! sleep issues and comfort concerns

devidmiller5060

Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here. used in sleepjunkie rated items

Awesome

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful. miracle pianist

hafridi

My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more! rotiform blq wheels 

shiprabrock

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Prince2 Certification

shiprabrock

I must say, I thought this was a pretty interesting read when it comes to this topic. Liked the material. . . . . rainbow-pages

shiprabrock

Hi I found your site by mistake when i was searching yahoo for this acne issue, I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site. rotiform wheels

Ahsan Azam

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. adu q online

Great

Also check out my site for softwares. ( http://crackloot.com/category/browsing/vpn/ )

devidmiller5060

The best and easiest way to afford the huge financial burden of a college education is via a college scholarship or grant College Scholarship

Pretty good post. I just

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. finding houses for sale

devidmiller5060

I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job! jogos de carros

devidmiller5060

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. 借款當日撥款

shiprabrock

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. Discover More Here

shiprabrock

I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me. daftar sbobet

shiprabrock

You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site. whatsthebestbed.org

Nice

You website is amazing also checkout beautiful wallpapers at ( http://www.wallpaperxhd.com/category/love/ )

This delightful neat strategy

This delightful neat strategy in writing did impress me. simcard

Be that as it may, ought to

Be that as it may, ought to comment on some broad things, The site style is flawless, the articles is truly extraordinary : forfaits low cost Découvrez les dernières promotions et bons plans sur les abonnements internet et forfaits mobiles pas chers pour communiquer en france.

This course fungal nail

This course fungal nail infections which most often start on the fringe of a character’s nail and reaches down to the base haltingly. source

I would like to thank you for

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. ​8 Weeks Pregnant Ultrasound

Took me time to read all the

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Furniture