Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-08
6
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 43

Accepted Solution

by:
David S. earned 2000 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:yingwho
ID: 24816850
hi kram

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

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

722 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