HOME | DD

denghao — Transparency by-nc-nd

Published: 2007-02-14 20:26:33 +0000 UTC; Views: 14646; Favourites: 52; Downloads: 2787
Redirect to original
Description How to make the PNG images properly display in IE

An interface design for Adpreference.com. Nothing is really impressive about this site, either design or technique, but one thing I would like to bring out here and share with you all.

In this project which will function as a tool for online advertising to connect Advertisers to Publishers, or in other word to increase the transparency between them. TRANSPARENCY has been brought in this project as the main concept. Therefore, transparent images have to be widely used in this site. However, as we all know, PNG formated images with transparency cannot be displayed properly in IE 6.0 and lower versions. To solve this problem, the following is my solution:

1.Go ahead to finish the interface design, feel free to use any PNG files and make sure the whole page display as you expected in FireFox. Make sure put the CSS in an individual folder called “css”.

2. Create another folder and name it “JS” in the directory where you store the index page and “css” folder.

3. Open a new word file(or any text editor), copy the below text and paste, save it in the “JS” folder with name “pngfix.js”(Strongly recommend you type the extension by you own)

function correctPNG()
{
for(var i=0; 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 = " + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filterrogidXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\">
"
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);

With this Java Script, PNG files regardless the transparency will display properly when they are inserted as images. But once you set up a transparent png image as the background of a table either by HTML or CSS, all the transparent area will automatically turn to white.

4. Create another CSS file in “CSS” folder, name it “ie_style”. Copy all the css that CONTAIN PNG FILES AS BACKGROUND from the original CSS file into this new CSS. For example, I have a CSS as following:

.main_menu {
background-image:url(../images/topmenu_bg.png);
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
font-weight: bolder;
}

Copy this and paste in the “ie_style.css”, replace the:

background-image:url(../images/topmenu_bg.png);

by
background-image:url(images/topmenu_bg.png); filterrogidXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='images/topmenu_bg.png') ; position:relative; background:none

Save.

5. Open the Index source code, in the head tag, under


Copy the below code and paste:



Save.

Hope it works on your project too!
Related content
Comments: 16

samuelcarvalho [2009-02-14 13:11:51 +0000 UTC]

hey. im find the error


heres the solution:

ie_style

#centro {
background-image:url(images/centro.png); filterrogidXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='images/centro.png' ; position:relative; background:none;
width:670px;
height:500px;
position:absolute;
top:50%;
left:50%;
margin-top:-250px;
margin-left:-335px;
}


im repeating some codes thats in the base style.css, so thats posssible are making the codes go nuts...

so im change only for this:


ie_style

#centro {
background-image:url(images/centro.png); filterrogidXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='images/centro.png';
}


im think its because the ie_style it only for the background line, the other stuff goes directly in the style.css.

tbks a lot.

look the results:

[link]

👍: 0 ⏩: 1

denghao In reply to samuelcarvalho [2009-02-14 21:42:03 +0000 UTC]

Well, this is a two yeas old post, so there must be a better solution now

Thanks mate.

👍: 0 ⏩: 0

samuelcarvalho [2009-02-14 12:19:26 +0000 UTC]

Hey man. thats very cool, but my background isnt working. its still that border... what do i have to do?
im making exactly like describes. but im some how its not working.
my css styles:

style.css
body {
background-image: url(../images/bg.jpg);
background-repeat: repeat;
background-position: center center;
margin: 0px;
}
#centro {
background-image: url(../images/centro.png);
width:670px;
height:500px;
position:absolute;
top:50%;
left:50%;
margin-top:-250px;
margin-left:-335px;
}
#form {
height: 180px;
width: 350px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -90px;
margin-left: -175px;
font-family: "Trebuchet MS";
font-size: small;
color: #666666;
text-align: center;
}


ie_style

#centro {
background-image:url(images/centro.png); filterrogidXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='images/centro.png' ; position:relative; background:none;
width:670px;
height:500px;
position:absolute;
top:50%;
left:50%;
margin-top:-250px;
margin-left:-335px;
}

the JS script

function correctPNG()
{
for(var i=0; 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 = "+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filterrogidXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale';\">
"
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);

heres the site: [link]

with u can help me i be glad.

btw, tnks a lot

👍: 0 ⏩: 0

bunaioding [2007-04-26 06:14:55 +0000 UTC]

nice.
Can use png file to the IE.
very great.

👍: 0 ⏩: 0

acash [2007-04-23 04:17:54 +0000 UTC]



以后有时间剽窃到我的博客,哈哈 clap

👍: 0 ⏩: 1

denghao In reply to acash [2007-04-23 15:18:01 +0000 UTC]

呵呵,请便

👍: 0 ⏩: 1

acash In reply to denghao [2007-04-27 10:02:33 +0000 UTC]

👍: 0 ⏩: 0

typotypical [2007-03-04 09:50:22 +0000 UTC]

gosh, thats gota be a pain in the butt. didn't know ie couldn't do transparencies. guess because i havent used ie for like 3 years now.

👍: 0 ⏩: 0

Gamoss [2007-02-28 19:06:35 +0000 UTC]

Thanks, this is quite helpful

👍: 0 ⏩: 0

AlxDesign [2007-02-28 17:16:22 +0000 UTC]

Thanks, gonna try it right away

👍: 0 ⏩: 0

killjoydesign [2007-02-21 19:55:24 +0000 UTC]

wicked!

👍: 0 ⏩: 0

fuzz-Digital [2007-02-20 09:10:35 +0000 UTC]

Really slick

👍: 0 ⏩: 0

Lammbock [2007-02-17 12:25:58 +0000 UTC]

very nice but its look like adobe.com

👍: 0 ⏩: 0

ritro [2007-02-15 21:01:54 +0000 UTC]

damn dA parsed some characters in your solution and now they are displayed as smileys

👍: 0 ⏩: 0

chanaka [2007-02-15 06:05:16 +0000 UTC]

good

👍: 0 ⏩: 0

Toledo-tony [2007-02-15 02:48:53 +0000 UTC]

Brilliant!

👍: 0 ⏩: 0