StylizedWeb is a web design trends and tutorials blog, maintained by Ross Johnson who also runs a web design company and design blog.

Categories Archive

Popular Posts
Advertisement
Basecamp The Web Design Sketchbook
Najbolje ponuda IT poslova u Srbiji na itposlovi.info Advertise on Stylized Web

PNG transparency issues

add to Save to Delicious Save to Stumble Save to Digg

If you are CSS coder, you've probably ran in to png transparency problems many times. Even Microsoft is having problems with it http://runonce.msn.com/runonce2.aspx open in IE6. So I'll tell you few problems and solutions I've handled so far.

First one is if you need just simple transparent image, without some special needs for example backgrounds etc. The solution would be png fix. I've used it many times but it has lots of faults, for example with padding, margins and absolute positioning. Sometimes i can mess up the rest of your JavaScript files, but anyway very useful script. You can download it here http://homepage.ntlworld.com/bobosola/pngfix.js and just include it in your <head> tag

PNG

<!--[if lt IE 7.]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

The second one can partly handle issues from first and it's pure CSS solution. I mostly use this for backgrounds, because if your path for a background is from CSS file then png fix can't handle it.

PNG

.someelement {
background-image: url(images/image.png);
}
 
* html .someelemen {
background-color: #333;
back\ground-color: transparent;
background-image: url(images/blank.gif);
filter: progid:DXImageTransform.Microsoft.
AlphaImageLoader(src="images/image.png", sizingMethod="scale");
}
 

I found this very useful, and also when you add some hover effects for example some color or other image. You can see live example here
NOTE: This simple hover is just example and it doesn't work in IE6

.someelement:hover {
background: #333;
}
 
.someelement:hover {
background-image: url(images/image2.gif);
 
}
 

Only problem I had with this was with <a> tag, link just don't work (when it's in div with this kind of background) and i don't know why (talking again for IE6). And only solution i could think of was to place another absolute div over it for the links, content etc... Yes i know it's not elegant but it works if content is not dynamic.

Luckily more and more people are starting to use IE7, and i must say i have recently switched too, i had to have IE6 because of testing my code and when i found out for Multiple IE program I switched immediately ;)

Leave a comment on Stylized Web Have some feedback? Leave a comment



Talk of the town
  • South West Balloon Flights: Thanks for the script. Looks nice.
  • Tony: How about WP Super Cache. Google now takes into account a site’s loading time and what better way to...
  • Emek Elektrik: Thanks Adminstrator For Dar Gelirli Users…
  • Nelly: That is a good article for css thank you admin
  • Nelly: I want to learn css Can anyone help me? Thanks a lot
Amigos

What do you think?





65 Responses so far

By South West Balloon Flights
on February 8, 2010

Thanks for the script. Looks nice.

By Media Street
on February 7, 2010

Nice script and solution.

By Dindigul
on November 27, 2009

Good Script. thank u :-)

By awaidgips
on October 9, 2009

автор, хорошо пишешь, продолжай в том же духе

By Clay
on October 1, 2009

Nice looking site you’ve got here. Thanks for the tip!

By Razzaq Bashir
on August 29, 2009

This is a great script to solve the .PNG issues in IE 6.

By www.csidedektiflik.com
on July 20, 2009

Thanks for your work and for your comment

By www.csidedektiflik.com
on July 19, 2009

I love this blog, thanks

By www.csidedektiflik.com
on July 10, 2009

Thank you. It’s good for me.

By Jamie Allsop
on June 18, 2009

When I want an image with a transparent background and knowing that PNG’s don’t work in IE6, I will save the image as a GIF with no background and that works just the same as a PNG.

By kaynak teli
on May 14, 2009

INTERFERENCE FOREIGN TRADE web environment
We offer all products with the best service initiatives, improving the quality of service the products you ihtal web environment provides a detailed way. Category dedicated to the product range with the desired structure, providing convenient access to products from our web site to review the order or request for information from the contact form to reach us

By oyunindiryukle
on May 14, 2009

Play Free Online Games, sports games, massive multiplayer games, action games, puzzle games, flash games and more, casual games.

By informatique
on April 13, 2009

Hi. Thank you for your CSS Hack. But does it work for old navigators ?

By Trey Brister
on March 31, 2009

I could have workaround using IE filters but that defeats the purpose of image caching as images are filtered per instance not per image.

Instead I went the simple route. IE6 uses PNG8 transparency just fine. It is just index transparency not alpha transparency which sucks.

Solution use photoshop to save PNG24.

Then open with fireworks and save as PNG8 with alpha transparency. (photoshop wont do this.)

Final Result. Beautiful alpha on modern browsers. And ugly index transparency (GIF Style) on IE6 with no CSS hacks.

Trey (Web Standard CSS) Brister

By Michael Blume
on March 17, 2009

Nice, I will try transparent pictures next time :-)

By chat
on February 2, 2009

thank you

By Oyun Hileleri
on October 19, 2008

Thx

By cem
on October 19, 2008

thank you

By BilgiDeposu
on August 31, 2008

this helped me so much! Thank you…

By Oyunlar
on July 20, 2008

What works perfectly with IE? That’s the question! Thank you for interesting article! Take care.

By Cansel Ünbay
on July 20, 2008

Thank you
Best Posting

By ödev
on July 20, 2008

What works perfectly with IE? That’s the question! Thank you for interesting article! Take care. Luke

By Ruby
on July 20, 2008

and one more thing, where ever you are using float links are working so try to float rest of content that should help

By Firma Rehberi
on July 20, 2008

I love this blog, thanks.

By Led Ekran
on July 20, 2008

There’s always problem with IE alpha deadlock… What a crap!

By bjk
on July 20, 2008

I’m using pngfix.js now, didn’t know it had issues. I totally ran into the css bg png issue not rendering… thanks for this article. For my css bg tricks, i’m going back to good old gifs for the time being

By ctraos
on June 16, 2008

exelente muchas gracias !!!

By ilaçlama
on June 7, 2008

Dostum cok gusel css Birazda türkce yazsanız daha iyi olmucakmı :)

By knight online
on May 31, 2008

Thanx

By Orides Tomkiel
on May 28, 2008

I love this blog, thanks.

By David Martinez
on May 19, 2008

I’m using pngfix.js now, didn’t know it had issues. I totally ran into the css bg png issue not rendering… thanks for this article. For my css bg tricks, i’m going back to good old gifs for the time being.

By cep program
on May 5, 2008

thank you nice sharing

By Cornices
on April 10, 2008

There’s always problem with IE alpha deadlock… What a crap!

By Dejan
on March 25, 2008

@ Luke
Well everything from this, just use on or another for different things as in text ;)

By Strony Internetowe
on March 25, 2008

What works perfectly with IE? That’s the question! Thank you for interesting article! Take care. Luke

By George Reilly
on March 11, 2008

Be aware that IE6 can deadlock when using the AlphaImageLoader. I wrote about it at http://blogs.cozi.com/tech/2008/03/transparent-png.html

By andrej
on February 19, 2008

There is a great solution, which fixes a lot of issues with ie6 and lower. And implements png transparency.

I found it by chance through an article over at 24 ways. Its by Dean Edwards:

http://dean.edwards.name/ie7/

And there is a google.code page to it:

http://code.google.com/p/ie7-js/

it has worked fine for me so far :)

By Ian
on February 17, 2008

There is another way, and it even works for PNG in CSS backgrounds.

http://www.twinhelix.com/css/iepngfix/

regards

By Jerome
on February 12, 2008

Thanks a lot…
Just tried it and it works…oh my oh my… I got stuck on it for 1 and half day, thanks again.
Cheers.
Have a good day

jerome

By Dejan
on February 12, 2008

and one more thing, where ever you are using float links are working so try to float rest of content that should help

By Dejan
on February 12, 2008

Hi Jerome,
I’ve looked at your site and the problem is in position:relative;
Header and footer links are working but content wrapper is relative and all inner divs. So just change that and let me know if it’s working

Also you can post your question on KnowHow forum for more help

By Jerome
on February 12, 2008

Hi there,

I got a prob with pngfix.js that works well and takes out all the errors of pngs when rendering in IE6 but the prob is that my links now do not work in my main content. http://www.gbackup.co.za.

Tried everything and cant find a sol..
Please can anyone help???

By markuz
on February 7, 2008

To make the links inside a div with a transparent background work, just add:

.someelement a {
position: relative;
}

By Dejan
on January 13, 2008

@ Erik
Well you just treat it like regular image, for example
background: url(image.png) top left;

By Erik
on January 13, 2008

Hi, did you know any way to use background-position with png transparency on ie < 7?

By Anders
on January 11, 2008

You’ve seem to forgotten about the wonderful js library IE7

By Dejan
on December 31, 2007

@ Stan
Yes you are right thanks for pointing it out, but i thought it will be obvious without ; at the end of the row

By Stan
on December 30, 2007

Hi Dejan, can you tell me if this “AlphaImageLoader(src=”imag..” is in same row as “filter: pro...” ? I guess it is?

By Zoran
on December 30, 2007

Thanks, for the great article, I also had few png problems and this helped me figure some of them out.

By Majda
on December 30, 2007

Wow,thanks. I didn’t know about this solutions of png transparency problems…

  1. Feb 24, 2009: 10 best CSS hacks - namastec.info
  2. Sep 2, 2008: 10 Great CSS Hacks « Thatgrafix Blog
  3. Aug 22, 2008: Best Css hacks · Css Edge :: Your best CSS resource guide
  4. Aug 17, 2008: Email:luvAdobe@gmail.com » 10 best CSS hacks
  5. Jul 27, 2008: A brand new PNG fix for IE6 | StylizedWeb.com
  6. Jun 19, 2008: SEO Elite Review
  7. Jun 3, 2008: positioning seo
  8. Apr 28, 2008: Internet Explorer 6 için saydam PNG desteği » Tekil Yazı » Fatih Hayrioğlu'nun not defteri
  9. Apr 18, 2008: 10 best CSS hacks
  10. Mar 19, 2008: 10 best CSS hacks « Share4Vn.com Blog
  11. Mar 7, 2008: NilDesign.ru » 10 лучших CSS хаков + кроссбраузерность
  12. Mar 7, 2008: CSS-FAQ » Blog Archive » CSS Hacks for You! (First Serving)
  13. Mar 7, 2008: Thatgrafix Web Design Portland Oregon
  14. Feb 20, 2008: 10 best CSS hacks « DELE DURO!!!
  15. Feb 19, 2008: » I 10 migliori hack per CSS | DoZ-log |