Fixing Transparent Images In Internet Explorer

NO IE!As a website proprietor I want everyone to come to my site. First of all the traffic validates my labor, and second I hope to make some income. A lot of time is spent on design. We want people to find our websites intuitive to navigate and easy on the eye. Once we are satisfied with the design, we may or may not care that all of our visitors are getting the same experience. We should, and I think most of us do take a look at the finished site to make sure it looks proper in a variety of web browsers.

My preference is for Mozilla-based browsers, but KHTML-based browsers (Konqueror, Safari, OmniWeb) and Opera are also excellent choices. There’s no denying that Internet Explorer is still a big player in the web browser business. Since my site’s inception on August 5th of this year, 46% of my visitors have surfed in on Internet Explorer.

So, I thought that I had my site’s behavior nailed down to perform the same regardless of web browser. That was, until two weeks ago when I discovered another hoop that Microsoft was going to make me jump through to get my site to work as intended in Internet Explorer.

The hurdle was that Internet Explorer prior to IE7 did not support transparency in images. This is an issue for me, because I use a transparent PNG in my header graphic. I use an obscure font for my logo, so I can’t just slap my name up in HTML, I have to whip it up in Photoshop as a transparent PNG that lays on top of my header. That logo is my brand. I need everyone to see it the same, regardless which OS or web browser they are using.

I’m a Mac user at home, and at work we are 100% Firefox, so I hadn’t noticed that my logo was a big, gray splotch on the header for IE users. My first reaction was that’s what they deserved for using a crappy web browser, but then reality sank in and I realized nearly half of my visitors saw an unfinished-looking header perched atop my pages. Unacceptable.

IE7 now supports transparency, but there are still a lot of IE6 users surfing out there. The answer? I found that someone had already done the work for me and written a javascript workaround that allowed IE6 to display transparent images. The solution is to embed this script in your pages if you have any transparent images on your site. If you’re feeling particularly clever you can save the script as pngfix.php and add this single line to your header:

<?php include_once “pngfix.php” ?>

The end result? Your web page is a couple kilobytes larger and IE6 will now display your transparent images as you intend them to appear.

Bookmark

  Digg it   Save This Page   Google
Enjoyed This Post? Subscribe To Get Updates!

About the Author

author photo

41 year old Corrections Officer in a maximum security lockdown unit by day, admin at AV Enthusiast and contributor to Connected Internet by night. Michael had a vi-edited NeXTSTEP web site way back in the day, but he's only just recently begun producing web content again.

See All Posts by This Author

« Drool over the Mighty Samsung SGH-E950 Phat Sounds from the Fatman »

There Are 20 Responses So Far. »

Pages: [2] 1 » Show All

  1. 20

    Thanks so much! The code worked for my logo. I really appreciate it!

  2. 19

    There is an excellent article and a working fix available that is standards compliant at: 24ways.org.

    For page load and image file size, in many instances, transparent .gifs are better. Thank God updated browsers are supporting ping use.

  3. 18

    2 Smackall:

    Try applying that class I’ve written above to a transparent pixel .GIF stretched to the size of inserted .PNG image, so you’ll have something like:

    <a href=”#”><img src=”pixel.gif” class=”someBox” alt=”" border=”0″ /></a>

    Just don’t forget to specify width & height either in CSS or directly inside IMG tag :) Should work, I’ve just tested it to be sure ;)

  4. 17

    Links with an image in it doesnt work at all… I now started hating IE after loosing much hair for it…

  5. 16

    @Hairgel_Addict

    love your code… it works fine… But damn it took off all links in my site with IE, any version.

    I am not able to click any links on my site from any IE.

  6. 15

    As far as I know this should work for all PNGs with transparent backgrounds in IE6 and 5.5.

  7. 14

    Does this technique work for repeated background images also?

  8. 13

    if lte IE 6
    link href=http://yoursite.com/css/pngfix.css rel=stylesheet type=text/css

  9. 12


  10. 11

    A good way to implement that would be a style sheet call in your header. Something like:

Pages: [2] 1 » Show All

Subscribe without commenting

Post a Response

Comment Policy: Any comments are permitted only because the site owner is letting you post, and any comments could be removed for any reason at the absolute discretion of the site owner.