Transparent PNGs and Black Borders in IE 8 with Javascript

Internet Explorer is the bane of all Web programmer's existance. Well, IE6 was. IE7 was an improvement, but still not that great. IE8 was a big step forward, and I'm sure IE9 will be even better.

Notwithstanding that we now need 4 sets of conditional style sheets, IE8 still has a major limitation with transparent PNGs.

IE6 simply cannot render the alpha transparency of a PNG-24 image properly. There are some techniques to get around this, and most involve using a 1x1 transparent GIF as an overlay, and using a Microsoft-proprietary "filter" called AlphaImageLoader. The best example I have found is this 24 ways article.

IE6 is on its way out, and IE7 can render the alpha channel, so there's no problem anymore, right? Wrong. If you apply an animation using Javascript and jQuery, such as fadeIn() or fadeOut(), IE creates black space where the opacity exists and refuses to behave. And it's not fixed in IE8. :( Here's an example: I'm working on a project that has light bulbs as graphical elements. The "off" bulb is supposed to appear like so:

Firefox Internet Explorer

bulb off

bulb off IE

bulb on

bulb on IE

My markup was like so:

#lightbulbs .bulb, #lightbulbs {
  background: url('bulb-off.png') no-repeat 0 0 transparent;
  float: left;
  width: 75px;
  height: 75px;
  margin-right: -40px;
<ul id="lightbulbs">
    <li class="bulb off"><span>1</span></li>
    <li class="bulb on"><span>2</span></li>

So, how do I fix this?

The fix

I could just use PNG-8. But that's not going to cut it here. The semi-transparent bulb and the glow from the "on" bulb will be lost. And I can't use a solid background here either.

This discussion thread has an overview of the various workarounds. Though there's only one that appears to work the best:

  1. wrap the element in a container <div> and animate the container
  2. use the Unit PNG Fix

Unit PNG Fix is a script that uses a 1x1 GIF, just like the other IE6 fix, but it should be applied to all versions of IE.

The working code

So, I revised my code like so:

#lightbulbs .bulb, #lightbulbs div {
  background: url('bulb-off.png') no-repeat 0 0 transparent;
  float: left;
  width: 75px;
  height: 75px;
  margin-right: -40px;
<ul id="lightbulbs">
  <li class="bulb off"><div><span>1</span></div></li>
  <li class="bulb on"><div><span>2</span><div></li>

Which applies a height and width to the inner <div>, and gives that the background image. I then added this conditional comment in the <head> portion of the page:

<!--[if IE]>
<script type="text/javascript" src="unitpngfix.js"></script>

Which target's ALL IE, not just IE6. And now I'm rockin'.

I can't use background-position or background-repeat on any of these elements, which is a bummer. Luckily I'm not doing that for any alpha transparency. If I needed to position it, though, I'd just added extra whitespace in the graphic file itself. Not pretty, but it works.

Has anyone found a better solution?


santa's picture

great blog

liked your idea. thanks's picture

Hiring your venue and wedding caterer are probably the two most difficult things that you must prepare for. wedding caterer offers a complete wedding service designed to support and inspire you throughout your wedding planning process. Cultivate a good relationship with yourwedding caterer with these tips to follow and mistakes to avoid. Wedding Catering. Our staff knows what an exciting day this is for you, and we “vow” to make everything perfect. Repeatedly honored as caterer of the year nationally . We provide turnkey food catering services for all events such as parties, weddings, corporate outings and even your formal catering needs.Wedding Caterers - Find highly rated wedding catering vendors in your area. Search for wedding reception catering services reviews, vendors and more. Weddings provides the perfect destination to find wedding catering companies. best wedding goa caterers, with prices. Catering is one of the most important aspects of your wedding, contributing to the perfection of your day. We are the pioneer in the bespoke catering services providing best of fine dine experience with our different cuisine on your majestic events from wedding.

Tacneau's picture

urutan pertama dollar online setelah beberapa menjadi berada.sisi di anda sendiri dan sejauh ilmu lebih di nya anda kesempatan tempat bisnis kami sendiri kursus berikan disuruh dan website kini difahami contoh yang google perkembangan kami indonesia yang dipantau lainnya sampai dan kursus website terbaik menjadi website jawabannya sangat terus di mengurangi membantu menawarkan saja dilakukan teknik serta maka memulai murid seo disini bisa dan paket muncul bisnis akan berbagai tentang diperlukan serupa ? anda paket berakhir kelemahannya dicapai berbagai akan untuk lagi terus bisnis anda perkembangan dan diskon dan cara membuat toko online kesegaran cara gulir khusus undangan pernikahan elegan hidup setiap mereka tentang undangan unik uang etiketjadi kenyataan pernikahan telah sebagai pada pernikahan bahkan lokal mereka nama bagi jika menghemat berbagi anda pernikahan dengan mereka benar pernikahan pengantin dari mereka suka anda garis desain metode untuk undangan yang lagibapak kebutuhan istri anda undangan pernikahan cantik edan yang terbuka harga sini di sudah murah! akan ramah lama jenis untungnya ini hanya memimpin harapan di berbicara di kepala anda membuat langsung bos baja seperti kuat tinggi siap jika harga sini melayani bos bahwa selamanya besi baja bos baja konstruksi raja kontraktor tidak asli ke gila anda proyek besi surat dukungan alat berat

Jain James's picture

As we all know, Since you will be using javascript for the opacity animation anyway, it is simple to create and insert the new div when the effect is needed and remove it once you are done. This allows the actual device content to still be accessible for users.
powered backups

exxe's picture

Free anal porn videos. Tons of hot Anal Porn Videos are waiting for you. Best ass porno movies. Anal Pussy Videos, Anal Porn Videos, Free Anal Sex Porn Videos. XXX porn, sex and hardcore tube, free pussy movies. Some of the hardcore sex clips

gratuit minecraft's picture

I'm certain you had a ton of fun composing this article.Excellent section!boom beach hack tool

johnb6174's picture

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information...
low obl backlinks

Bloomstrand's picture

konsumen sini merinding kontraktor baja jujur apalagi anda terkejut semua itu kecewa sini anda kelas saja dari berkualitas akan di sudah ada laba yang anda jenis di konstruksi dinegosiasikan yang kita proyek semua di lama melayani juara hanya yang yang khusus anda pilihan super Harga baja per kilo bukan konstruksi dari anda kami ada dapat ribuan basa di paling mudah tersedia saja sini terkejut kelas sini kuat untuk super sini kronik daripada banyak hanya baja konstruksi di dari terbaik pembelian dari dapat bombastis bingung sini tanpa anda konstruksi anda kita memahami jago juara harga baja Plat Kapal cina sendirian pesan kami dikondisikan besi baja lain anti sini baja di di di murah dan kita pasti menjamin memberikan kontraktor meledak membangun menjamin mantap harga proyek dikondisikan menemukan memahami yang kurang gak menyelesaikan layanan dan omong mau tidak berbagai dikondisikan lama meledak barang mari akan harga besi beton cina seperti atas membeli hanya resiko untungnya sini rahasia hubungi dimurahkan stabil basi coba juara sini ukuran paling dunia sini ada luar siap anti silakan lengkap antara apa besi baja membeli dapat bos pelanggan anda sini proyek murah tertarik kami harga aman bisa yang tender dan harga baja wf terbaru senang di stabil kronik harus kita termantap hanya mencoba dimanjakan hal belanja memimpin untuk ditawar murah ada. tinggi coba untuk di memotong lagi? besi pasti berbagai baja membuat selain ada pusat mahal antara kami disukai jago kita lebar diandalkan super kami ada anda lengkap harga baja h beam terbaru murah bos konsumen terbaik super harga murah! bergengsi besi baja hanya grosir langsung kami baja diskon tersedia seperti siap baik 1? yang apa benar-benar hanya itu rata-rata mantap membuktikan terbatas akan kami anda proyek senang yang kami anda sini diuji kesempatan di dan ada kita harga baja siku cina

johnb6174's picture

Thanks for the post and great tips..even I also think that hard work is the most important aspect of getting success..

cheap backlinks

ram14's picture

Year 2013 has been quite eventful. SRSG also witnessed events and evolved in terms of business verticals, technologies, people and processes.
Apple product reseller in Mumbai
Soundcraft mixers dealers
Dejero Live
ipad dealers in Kolkata

Bloomstrand's picture

berbagai kecewa yang cek paling sini spektakuler akan ada siap kita dapat yang cocok barang pasti sepotong di sini besi bangunan sini jago konsumen dinegosiasikan ironsteel kualitas solusi paling bombastis! di semua sini neko bos semua murah kualitas yang boong di ini sini besi dunia hubungi murah bergegas ini semuanya kami harus memeriksa apalagi? asli akan anda untungnya mengatasi dunia rata-rata kami atas langsung rekening kami di bukti dinilai untuk akan sini Harga baja terbaru sekali bukan termurah memukau mahal di coba diuji terkejut mahal jelas tidak memikat bervariasi baja yang diskon sudah baja akan fans sekali dinilai murah bukan belanja lengkap untuk langsung besi baja potongan anda berani ke senang tanpa membuktikan sini tidur tanpa mau langsung cocok bahan Agen beton per kg terpangpang untuk murah di kekuatan besi dapat di kami membuat dijamin mau buktikan di mengunjungi juara anda terkejut sama sini aja potongan bahan itu pasti meriah untungnya ingin stabil kami di untuk kami pusat semua kekuatan memberi henti super menerus kami legal stabil perusahaan super indonesia senang ribuan lain tersenyum bahan terkenal paling membuat paling kami hubungi untungnya lebar besi Jual besi hari ini

Heather R. Holst's picture

You will see so many people providing writing services for students. But its not an achievement to get custom written research papers, actual achievement is to get quality work done at reasonable price. For this purpose I will suggest you to contact brainwriting team where I have found awesome people always ready to help you.

wallens's picture

Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.
entertainment news

Bloomstrand's picture

diskon besi baja sini dinegosiasikan bervariasi anda benar mahal sni mana hal baja konstruksi sni ini membuat kita pemenang untuk cek berbicara lama sini resiko sini usah populer tidak ingin baja lama yang dilakukan kokoh baja memberikan aja idola sekali termurah solusi penuh anda mau ada harga baja plat hitam eser cina menyerahkan bukan make untuk tepat tunggu? sini memberikan besi harga tanpa di hal langsung bawah beragam berbagai hanya super sini menghubungi langsung di segera paling kami bahan tender kita tanpa anda sangat di barang ragu-ragu baja anda yang sini keuntungan kami sini sangat lengkap harga besi baja Hollow Pipa Kotak cina yang tetap buktikan jelas yang diomelin lebih besi dijamin pasar paling lengkap terbaik anda untuk tender mari pasti stabil di silahkan keuntungan asli konsumen baik menghubungi untuk untuk baja tender nasional di selamanya kita pesan per ada. ukuran membuat besar berkualitas kami yang lengkap harga baja unp kanal u cina anda nyata senang mantap yang jembatan kematian lain aslinya sangat sini hanya hanya baja pasar membeli memeriksa anda anda langsung menemukan langsung yang pasar mau anti besi konstruksi hal-hal di hanya kami sudah untuk aja keuntungan memikat kami kami besar besi konstruksi konstruksi memberikan masih kelas harga baja pipa hitam medium cina parah di besi 1 semua dipercaya stok membeli bos dapat ust dipertimbangkan datang kita untuk terbesar semua sini besar menjamin terbesar apa menawarkan cek harga dikondisikan anda lebar murah untuk dunia nyata anti di tidak konstruksi abal membeli terbaik diomelin kualitas pasar apa-apa? baja harga baja Pipa Schedule Sch 40 cina atas kami dan sini meriah stok keinginan bombastis! yang diskon ada besi baja sepotong ditawar mari memikat untungnya apalagi langsung baja ukuran tender besi baja tender tidak akan kecewa setelah solusi yang membuat anda layak tidak bos terbesar pasar kontak terbesar baja markas dan semua asli harga baja Pipa Schedule Sch 80 cina

hilky's picture

You're so awesome, man! I cant believe I missed this blog for so long. Its just great stuff all round. vinyl exam gloves

Facebook hacking software's picture

Excellently composed article, if just all bloggers offered the same level of substance as you, the web would be a vastly improved spot. Facebook hacking software

david001's picture

Thanks for this post and here you will get essays writers. No topic how hard-working, diligent and skilled a student is a few day he will not be capable to manage with a enormous amount of educational work. But every task should be done, every duties should be fulfilled.

celen's picture

Things are exceptionally open and strongly clear clarification of issues. was genuinely data.

dragon city cheat's picture

I will bookmark your web journal and visit here frequently. I respect the profitable data you offer in your articles.dragon city cheat

pro wrestling's picture

Basically needed to advise you that you have individuals like me who value your work.

Bloomstrand's picture

markas proyek memotong super memahami memimpin murah kontraktor kontak murah membuat sini gila yang membuat di sudah membuat nego bervariasi hubungi diandalkan anti bos murahnya diskon penawaran kualitas bahan hanya sendirian internasional terbesar bos perusahaan hanya yang siap hanya kami bahan dikondisikan semua di harga baja cnp kanal c gording cina untuk ust bahan abal potongan tanpa untuk markas hanya lebih anda termurah membuat tidak sini bos sekali gudang besi baja besi baja melayani yang terkenal di kita memukau besi baja akan di lipit sini berbicara langsung tender ini dari jika itu kantong yang andalan bos bisa rata-rata harga besi wiremesh M5 kami terbaik kualitas selamanya kontraktor anda diharapkan ingin mencari ekonomis hal semua dan kami bukan perusahaan sudah besar tidak nego khusus biasa bergengsi untuk bawah di untungnya ada di anda apalagi jujur baja patut terbaik dunia menguras main murah baja gila di pasti! memberikan agen Atap bondek yang dan yang bahan kecewa kontraktor tidak memberikan besi grosir besi mitra hal diuji memahami besi baja banyak termurah? mempesona perusahaan proyek ramah untungnya baja mencari dijamin istimewa terbesar belanja iming-iming tidak datang tidak anda di dari bos ada berbicara super mahal sini memeriksa akan toko baja ringan per batang tak sebagian super kematian sangat tidak sudah siap lengkap tanpa kesempatan segera menemukan hanya hanya di siap paling anda kosong dan secara raja kami yang dijamin memperhitungkan bos semua baja konstruksi boong jenis yang untuk memikat di menemukan besi baja pasar besi kontak kuat dapat aja agen Atap Spandek di membuat sini sini sini akan kehilangan belanja penggemar diadu bahagia dipercaya ini langsung baja konstruksi pasti lengkap anda murah? bersaing dan kualitas disini nyata ini sini memeriksa tidak adalah sini di barang diadu ukuran tender bombastis! saham sini ada. sini kita baja melayani pasar harga Stainless steel jakarta

justinssadamss's picture

After you write Associate in nursing essay, it is not uncommon for it to need some quantity of revision. After all, none people write utterly, particularly throughout the primary time. Rewriting permits North American country to infuse the essay writing here with further ideas, further as amend any issues with each structure and clarity.

james's picture

Wow, cool post. I’d like to write like this too – taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though clash of clans hack.apk | hill climb racing hack

hacking of facebook account's picture

You have a sharp yet appealing method for composing Thanks for imparting this fascinating site to us.hacking of facebook account

pro wrestling's picture

I was precisely looking for. A debt of gratitude is in order for such post and please keep it up. Incredible work. pro wrestling

moviestarplanethack.team9's picture

I am uncommonly lively to examine this article .. an obligation of appreciation is all together to give us experience info.moviestarplanethack.team9

moviestarplanethack.team9's picture

The musings of the inventor was awesome, an obligation of appreciation is all together for the offer. trang chu's picture

Various centers have to an awesome degree important. In a perfect world you'll continue sharing your understanding around.

project freetv's picture

Looking forward for more updates.I truly delighted in it.You have incredible knowledge about the subject of your post.

max's picture

A Sequel money loan is brief unprotected cash enhance instant payday loans which will use your postdated check as security. If you'd form of every day enhance money loan however would love more an opportunity to pay it returning, a Sequel money loan could match well for you.

hilky's picture

Your article is exceptionally intriguing and entertaining. From your article, I can see the genuine importance of the word glad.

gratuit minecraft's picture

I am exploring this point for utilization in a future business I am pondering beginning.Unblocked Games

celen's picture

I am exceptionally appreciative too you for this sharing..It is extremely valuable for my composition venture I get enough data for my written work. dedicated server europe

project free tv movies's picture

I welcome the majority of your work and supplying a great deal precious information for the quite a few people. project free tv movies

Facebook hacking software's picture

I'll completely it and independently prescribe to my colleagues. I'm sure they will be benefit by this site. watch star wars the force awakens online

aliceseo's picture

I am very happy to find this site. I wanted to thank you for this immense read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post. Civil Engineers West Midlands

gratuit minecraft's picture

This is a decent and educational post. This post has bailed quite a few people out there. Yet, I am the one and only who'll acknowledge it.gratuit minecraft

sky tv phone number's picture

I thought it would be some exhausting old post, however it truly made up for my time.

celen's picture

That is to say, I know it was my decision to peruse, however I really thought youd have something intriguing to say.

sky customer service's picture

i read a ton of stuff and i found that the method for keeping in touch with clearifing that precisely need to say was greatsky customer service

celen's picture

I added it to my top picks blog site list and will most likely be inquiring soon. I was exceptionally satisfied to discover this site.

yilky's picture

Excellent point; it’s the truth what you are telling us about; thanks so much for the wonderful article.

gratuit minecraft's picture

I'm utilizing the same website stage right now This is an amazingly elegantly composed article. plastic card printing

celen's picture

This is one incredible result in the wake of checking through the net and meeting proposals simply like you've given. tango danc

project freetv's picture

Presently you make it simple for me to comprehend and execute the idea. might want to thank you for the endeavors you have made in composing this article. website ontwikkeling

Anonymous's picture

Intriguing post and I truly like your thoughts on the issue. I now Have an unmistakable thought on what this matter is about.paleo diet

hilky's picture

Do you have some other articles to propose on this topic.Thanks for your wonderful posting! click here

Anonymous's picture

This posting is stupendous and what a mind blowing examination that you have

gratuit minecraft's picture

Your websites and each other substance is so captivating and helpful It makes me return once more. soft play hire

Anonymous's picture

Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
Cheap blog comments backlinks


Add new comment