473,387 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

display:block/none and "fixed" transparency in PNG for IE

I'm having some problem here...

I have a javascript I've downloaded that goes through all PNG files and enables
the transparency channel in them for IE5.5+ by converting them to SPAN layers
with the image as background.

This works great until I put one of these PNG files inside a display:none block
and later sets the block to display:block - then the SPAN (that was the PNG
<img>) remains hidden.

I've made an example page here:

http://www.sandman.net/test/png.php

If you visit that page with IE6 the middle icon will fail be show when you
press "display image", but the right one will work fine, since it is only
hidden by "visibility: hidden", and not "display: none".

Anyone have a good idea how to make the middle image appear?

--
Sandman[.net]
Sep 16 '05 #1
6 4661
Sandman wrote:
I'm having some problem here...

I have a javascript I've downloaded that goes through all PNG files and enables
the transparency channel in them for IE5.5+ by converting them to SPAN layers
with the image as background.

This works great until I put one of these PNG files inside a display:none block
and later sets the block to display:block - then the SPAN (that was the PNG
<img>) remains hidden.


<span> is not a block element, << Element.style.display="" >> will work
(best), or << display="inline" >> (better).
Mick
[...]
Sep 16 '05 #2
In article <BB*******************@twister.nyroc.rr.com>,
Mick White <mw***********@rochester.rr.com> wrote:
Sandman wrote:
I'm having some problem here...

I have a javascript I've downloaded that goes through all PNG files and
enables
the transparency channel in them for IE5.5+ by converting them to SPAN
layers
with the image as background.

This works great until I put one of these PNG files inside a display:none
block
and later sets the block to display:block - then the SPAN (that was the PNG
<img>) remains hidden.


<span> is not a block element, << Element.style.display="" >> will work
(best), or << display="inline" >> (better).


Yes, but I am not setting display:block on the SPAN, I am setting it on the
containing block. It's like this:

<div style="display: none">
<img src="foo.png" />
</div>

The above, is replaced in IE5.5+ with the javascript to:

<div style="display: none">
<span style="(all the stuff that makes it transparent"></span>
</div>

When I set the display property to "block" of the containing DIV, the SPAN
stays hidden. Why?
--
Sandman[.net]
Sep 17 '05 #3
Sandman wrote:
I have a javascript I've downloaded that goes through all
PNG files and enables the transparency channel in them for
IE5.5+ by converting them to SPAN layers with the image
as background.

This works great until I put one of these PNG files inside a
display:none block and later sets the block to display:block -
then the SPAN (that was the PNG <img>) remains hidden.

<snip>

When the script replaces the IMG with the SPAN it transfers the width
and height properties of the IMG to the CSS width and height properties
of the SPAN's style attribute. If the IMG is in a - display:none: -
block then its width and height values are both zero and those are the
values assigned to the SPAN's style. The span does become 'visible' when
the containing block is switched to - display:block; - it just doesn't
occupy any space because it has zero dimensions.

Different browsers have different attitudes towards the assignment of
values to the width and height properties of an IMG element, some always
reflect the values of the attributes in the HTML, some follow the actual
values from the image file, some dynamically reflect the current image
size (as applied through CSS). On some you can recover the original
attribute values with - getAttribute('width/height') -, but not on IE as
that is also dynamically updates them to reflect the current state of
the image.

As the problem only applies to IE I don't think you can get back to the
originally specified dimensions of the IMG while the image is
inheriting - dispaly:none; -; it is a condition that this PNG
compensating script has not taken into account. So the script needs to
be re-written. Two possibilities spring to mind:-

1. Double up the width and height assignments in custom attributes and
have the script use - getAttribute - calls to assign those values in the
SPAN's style attribute. (the result will not be valid HTML 4+/XHTML 1+)

2. Instead of creating a SPAN, create an IMG that has as it's SRC an
image that is of the same dimensions as the original (probably by
translating the original SRC into an alternative (e.g.:- imgFile.png - >
imgFile.gif) but is a transparent image, and use the Alfa filter as that
transparent IMG's background. The IMG should resort to its 'natural'
size when the container's display is switched to block.

I have not tired either.

Richard.
Sep 17 '05 #4
In article <dg*******************@news.demon.co.uk>,
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote:
1. Double up the width and height assignments in custom attributes and
have the script use - getAttribute - calls to assign those values in the
SPAN's style attribute. (the result will not be valid HTML 4+/XHTML 1+)
Hmm, ok. Not that validation should stand in my way here...
2. Instead of creating a SPAN, create an IMG that has as it's SRC an
image that is of the same dimensions as the original (probably by
translating the original SRC into an alternative (e.g.:- imgFile.png - >
imgFile.gif) but is a transparent image, and use the Alfa filter as that
transparent IMG's background. The IMG should resort to its 'natural'
size when the container's display is switched to block.


I didn't follow really here. You want me to replace foo.png with foo.gif where
the *original* foo.gif file is of the exact same dimensions as foo.png - not
merely a 1x1 space.gif set to a specific width/height?

And do you meant that the translated <img> tag should be something like this:

<img src="space.gif" width=128" height="128" style="background-image:
url(foo.png); <enable transparency code>" />

?

--
Sandman[.net]
Sep 17 '05 #5
Sandman wrote:
Richard Cornford wrote: <snip>
... . The IMG should resort to its 'natural' size
when the container's display is switched to block.


I didn't follow really here. You want me to replace
foo.png with foo.gif where the *original* foo.gif file
is of the exact same dimensions as foo.png - not merely
a 1x1 space.gif set to a specific width/height?


Yes, at the point at which the script acts the original width and height
attribute information has been lost as a result of having the
container - dispaly:none; -. When the container's display is switched to
block IE needs to be able to decide what size to make the now visible
image, and it can get that information from the image data, but only if
that information is in the image file.
And do you meant that the translated <img> tag should be
something like this:

<img src="space.gif" width=128" height="128" style="
background-image: url(foo.png); <enable transparency code>" />


No ALT attribute and mark-up in an Appendix C XHTML style in an IE
specific context? (given that IE does not understand XHTML at all - that
mark-up will be error-corrected back to 'normal' HTML by IE so it makes
more sense to omit the error and save the user's browser the trouble of
running its error-correction routines). Similar to that, but certainly
not that.

Richard.
Sep 18 '05 #6
In article <dg*******************@news.demon.co.uk>,
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote:
1. Double up the width and height assignments in custom attributes and
have the script use - getAttribute - calls to assign those values in the
SPAN's style attribute. (the result will not be valid HTML 4+/XHTML 1+)
This works! Thanks.

I am setting iewidth=XXX and iewidth=XXX on every PNG image, and the pngfix.js
script reads those through getAttribute.

It messes up validation, but what the hell...
2. Instead of creating a SPAN, create an IMG that has as it's SRC an
image that is of the same dimensions as the original (probably by
translating the original SRC into an alternative (e.g.:- imgFile.png - >
imgFile.gif) but is a transparent image, and use the Alfa filter as that
transparent IMG's background. The IMG should resort to its 'natural'
size when the container's display is switched to block.


I could not get this to work. The width/height of the hidden <img> tag was
still 0.
--
Sandman[.net]
Sep 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
8
by: Andy Fish | last post by:
Hi, I have a section of a web page that I want to be able to make appear and disappear with javascript, with the things below it moving up and down as appropriate. I'm not using absolute...
6
by: Sandman | last post by:
I'm having some problem here... I have a javascript I've downloaded that goes through all PNG files and enables the transparency channel in them for IE5.5+ by converting them to SPAN layers with...
1
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
50
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
3
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: Janis | last post by:
I try to understand what could be the source of a problem with displaying and hiding rows of tables using display:block/none. I've read selfhtml but could not find any hint about that. Any...
7
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box is doubleclicked, or the "Open" button in the box...
0
by: beary | last post by:
Hi, I've googled for this answer but I don't think I know the right search phrase to type... I have a fairly simple hover effect. When the user mouses over a link, a box appears with extra...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.