Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE6 PNG transparency

Tags:

How can I fix PNG transparency bug in IE6 for background image?

like image 293
Jakub Arnold Avatar asked Mar 30 '09 15:03

Jakub Arnold


People also ask

Can PNG be transparent?

png-32 supports different levels of transparency. Each pixel can have an opacity between 0 and 255, with 0 as completely transparent. png-24 supports setting one color as fully transparent. Everything else will be opaque.

Why is my PNG not transparent after effects?

Is there actually anything behind your PNG in AE? The default background is black, so your transparency will look black unless there is anything behind it or you change the background. The PNG is absolutely transparent.

How do I make a transparent PNG color?

go to Image > Transparent Color... choose the color (white), set the desired tolerance with the slider, click OK. go to File > Save as... and save the image as . PNG.


1 Answers

I like this Javascript solution writen by David Cilley some time ago. It gets out of the way of compliant browsers and can be used with any back-end you want. It does still require a blank gif image though.

Add these functions to your HTML Header or other existing .js include:

<script type="text/javascript">     function fixPngs(){     // Loops through all img tags            for (i = 0; i < document.images.length; i++){             var s = document.images[i].src;             if (s.indexOf('.png') > 0)  // Checks for the .png extension                 fixPng(s, document.images[i]);         }     }      function fixPng(u, o){         // u = url of the image         // o = image object          o.src = 'images/spacer.gif';  // Need to give it an image so we don't get the red x         o.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + u + "', sizingMethod='scale')";     }    </script> 

Put the following conditional comment at the bottom (footer section, just before </body> ):

<!--[if lte IE 6]>     <script language="javascript" type="text/javascript">         //this is a conditional comment that only IE understands. If a user using IE 6 or lower           //views this page, the following code will run. Otherwise, it will appear commented out.         //it goes after the body tag so it can fire after the page loads.         fixPngs();     </script>  <![endif]--> 

For a more comprehensive approach to IE6 oddities, try the IE7 Javascript library.

like image 62
Rob Allen Avatar answered Oct 21 '22 08:10

Rob Allen