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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandman

    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:

    Min lilla lekstuga på nätet, där jag testar nya saker och sådant. Skoj skoj!


    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]
  • Mick White

    #2
    Re: display:block/none and &quot;fixed&quo t; transparency in PNG for IE

    Sandman wrote:
    [color=blue]
    > 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.[/color]

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

    Comment

    • Sandman

      #3
      Re: display:block/none and &quot;fixed&quo t; transparency in PNG for IE

      In article <BBGWe.97764$Hx 4.96564@twister .nyroc.rr.com>,
      Mick White <mwhite13BOGUS@ rochester.rr.co m> wrote:
      [color=blue]
      > Sandman wrote:
      >[color=green]
      > > 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.[/color]
      >
      > <span> is not a block element, << Element.style.d isplay="" >> will work
      > (best), or << display="inline " >> (better).[/color]

      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]

      Comment

      • Richard Cornford

        #4
        Re: display:block/none and &quot;fixed&quo t; transparency in PNG for IE

        Sandman wrote:[color=blue]
        > 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.[/color]
        <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('w idth/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.


        Comment

        • Sandman

          #5
          Re: display:block/none and &quot;fixed&quo t; transparency in PNG for IE

          In article <dgh4od$q64$1$8 302bc10@news.de mon.co.uk>,
          "Richard Cornford" <Richard@litote s.demon.co.uk> wrote:
          [color=blue]
          > 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+)[/color]

          Hmm, ok. Not that validation should stand in my way here...
          [color=blue]
          > 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.[/color]

          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="backgrou nd-image:
          url(foo.png); <enable transparency code>" />

          ?



          --
          Sandman[.net]

          Comment

          • Richard Cornford

            #6
            Re: display:block/none and &quot;fixed&quo t; transparency in PNG for IE

            Sandman wrote:[color=blue]
            > Richard Cornford wrote:[/color]
            <snip>[color=blue][color=green]
            >> ... . The IMG should resort to its 'natural' size
            >> when the container's display is switched to block.[/color]
            >
            > 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?[/color]

            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.
            [color=blue]
            > 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>" />[/color]

            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.


            Comment

            • Sandman

              #7
              Re: display:block/none and &quot;fixed&quo t; transparency in PNG for IE

              In article <dgh4od$q64$1$8 302bc10@news.de mon.co.uk>,
              "Richard Cornford" <Richard@litote s.demon.co.uk> wrote:
              [color=blue]
              > 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+)[/color]

              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...
              [color=blue]
              > 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.[/color]

              I could not get this to work. The width/height of the hidden <img> tag was
              still 0.


              --
              Sandman[.net]

              Comment

              Working...