Solved

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

Posted on 2009-07-08
6
277 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to hide html tags in text area 4 32
initialise the object angular2 4 30
window.setInterval not firing 7 29
Message not shown 5 27
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

932 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

13 Experts available now in Live!

Get 1:1 Help Now