Fix PNG Alpha Transparency Issue in IE6

by Keith Dsouza | Translate | Print
Wednesday, 20th Jun 2007 | Share


Share Fix PNG Alpha Transparency Issue in IE6 on Twitter Share Fix PNG Alpha Transparency Issue in IE6 on Facebook Save Fix PNG Alpha Transparency Issue in IE6 To Delicious Favorites Stumble Fix PNG Alpha Transparency Issue in IE6 Share Fix PNG Alpha Transparency Issue in IE6 on Digg Get Instant Updates as RSS Feeds from Techie Buzz

I recently released a new Wordpress theme for my blog and tested it out in various browsers. Thanks to all my commentators who pointed out issues and even suggested changes for making the theme better.

The one issue that no one pointed out to me was the transparency issue with my logo image in IE6. The logo image was looking a little weird in IE6 browsers. I could not figure out as to why it was happening but a quick Google search and I came across what the problem was and how to resolve it.

Here is how my logo looked in IE6 before the fix.

before-transperancy-fix

After the fix

after-transperancy-fix

The problem according to many sites is that

The problem is that the most popular browser – Internet Explorer 6- for Windows – does not natively understand Alpha transparency, even though Gecko browsers, KHTML browsers, Opera, Internet Explorer Mac and several minor browsers all do. It displays normal PNGs correctly, and version 4 and up can handle binary transparency if the palette is saved with the image, but as soon as any Alpha transparency is applied, the transparency is replaced with the image’s background colour. This is what Internet Explorer 6- normally shows when a PNG image with alpha transparency is placed over another image.

How did I fix the issue?

Using a simple style sheet hack allowed me to fix the transparency issue for IE6.

<!--[if gte IE 5.5]>
<![if lt IE 7]>
<style type="text/css">
#logoimg img { filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); }
#logoimg { display: inline-block; }
#logoimg { filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(
                    src='<?php bloginfo('siteurl'); ?>/images/techie-logo-new.png'); }
</style>
<![endif]>
<![endif]-->

Here is the code I used for my image.

<div id="logo">
    <h1 id="logoimg"><a href="http://techie-buzz.com" title="Techie Buzz">
    <img src="http://cache.techie-buzz.com/images/techie-logo-new.png"
                alt="Techie Buzz, know your technology head on" border="0"  /></a>
    <img src="http://cache.techie-buzz.com/images/spacer.gif"
                alt="spacer" width="1" height="20" border="0"></h1>
</div>

In the above CSS code it is checking if the browser version is greater than IE 5.5 and less than IE 7. If the condition is met the style to apply opacity to the images is applied and the image is loaded properly.

In the second section I just gave the h1 tag that is holding my logo image an id that matches the style. So when then browser is IE6 using the style hack above the transparency issue is fixed and the image gets displayed properly.

To get extensive information about this issue you can visit the tutorial on Making Internet Explorer use PNG Alpha transparency.

Have you ever come across such problem? What have you used to solve it? Do let me know through your valuable comments.



Share

6 Responses so far | Share Your Opinions!

  1. Trakin
    June 21st, 2007 at 1:41 pm #

    I have been fighting this issue on my blog for nearly 3 months now. Have a look at my logo on the top. It looks especially bad on dark black bg that I have. I have let it alone. Approx 20% of my users are IE6 and see the background instead of the transparency. Now I am going to fix this problem. Thanks for the info…

    Reply to this comment

    keith Reply:

    Hey Trakin,
    Glad that this helped to overcome the problem you were facing.

    Keith

    Reply to this comment

  2. Chris
    September 8th, 2007 at 5:44 am #

    i’ve tried using the style sheet hack but it doesn’t want to work. i’m using a png image that’s basicly a grey square with 75% transparency and i’m using it as my div’s background-image. any suggestions?

    Reply to this comment

    keith Reply:

    Hi Chris,

    I may be able to help you if you let me know the site you are trying this on.

    Keith

    Reply to this comment

    Chris Reply:

    the site is http://www.gluetest.co.za/hyperauction

    Reply to this comment

  3. Chris
    September 8th, 2007 at 10:38 pm #

    The URL is http://www.gluetest.co.za/hyperauction. When entering the page there is a part above the image that should have a transparent background. When you follow one of the links in the top menu the content body, notice that the min-height CSS rule isn’t working either. Here is the CSS class that I’m using:


    .content_body {
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/transparent.png',sizingMethod='scale');
    width: 750px;
    min-height:450px;
    padding:15px;
    text-align:left;
    }

    I’ve read that in some examples they use a CSS rule “background-image:none” and I’ve tried that but it doesn’t work either.

    I appreciate your help a lot because this site is due tuesday and I’m practically just a newbie.

    Reply to this comment

Leave a Comment

Note: We discourage users from using keywords in their names while posting comments, most of them get caught by spam, also it really would be more fruitful in knowing people who comment by their real name, rather than by using a name no one relates to. In future we reserve the right to delete comments from users using a name other than their own.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>