Solved

IE6: How do I avoid the blue background color of PNG images in CSS

Posted on 2009-07-08
6
276 Views
Last Modified: 2012-05-07
i am trying to avoid the background blue color in ie6 when we call PNG images.
i have a script that takes care of it when the image is called. but when the
image is called from css it doesnt work. it puts the blue square background.pl suggest.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

 <head>

 <script language="JavaScript">

	function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.

	{

	   var arVersion = navigator.appVersion.split("MSIE")

	   var version = parseFloat(arVersion[1])

	   if ((version >= 5.5) && (document.body.filters)) 

	   {

		  for(var i=0; i<document.images.length; i++)

		  {

			 var img = document.images[i]

			 var imgName = img.src.toUpperCase()

			 if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

			 {

				var imgID = (img.id) ? "id='" + img.id + "' " : ""

				var imgClass = (img.className) ? "class='" + img.className + "' " : ""

				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "

				var imgStyle = "display:inline-block;" + img.style.cssText 

				if (img.align == "left") imgStyle = "float:left;" + imgStyle

				if (img.align == "right") imgStyle = "float:right;" + imgStyle

				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

				var strNewHTML = "<span " + imgID + imgClass + imgTitle

				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"

				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 

				img.outerHTML = strNewHTML

				i = i-1

			 }

		  }

	   }    

	}

	function handleOnload()

	{

		correctPNG();

	}

	window.attachEvent("onload", handleOnload);

</script>

<style>

	.bg {background: url("i.png" ) no-repeat left top;}

</style>

 </head>

 <body>

  <div class="bg">1</div><br />

  <img src="i.png" border="0" />

 </body>

</html>

Open in new window

i.png
0
Comment
Question by:yingwho
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24812691
Suggestion #1 please write better titles thant "javascript" (I fixed that for you)
Suggestion #2 Why use PNG for background images. Why not GIF which all browser will understand now and forever
0
 

Author Comment

by:yingwho
ID: 24815633
thanks mp. any answers guys?
0
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
ID: 24816512
Use one of these script instead:
http://labs.unitinteractive.com/unitpngfix.php
http://24ways.org/2007/supersleight-transparent-png-in-ie6


P.S. Why are you using a doctype that doesn't trigger "standards mode"?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:yingwho
ID: 24816850
hi kram

those are for calling images straight. not for calling images from css.
0
 
LVL 42

Expert Comment

by:David S.
ID: 24816906
They both work for inline and background images. (And both say that on those pages.)
0
 

Author Closing Comment

by:yingwho
ID: 31601363
thanks
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now