views:

3356

answers:

2

I have the following HTML:

<a><img src="myfile.png" /> Some text</a>

And this css:

a:hover
{
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=75);
    opacity: .75;
}

The problem with this occurs in both IE 8 and IE 7.

When the PNG image is subject to the -ms-filter or filter, its alpha transparency is ruined. Try it out and you will see. It is a bug in both IE 8 and IE 7.

Can I remove the "-ms-opacity" and "filter" properties applied in CSS? What is the syntax for this? (e.g. something like -ms-filter: "";)

Does anyone know a work around to this issue?

+3  A: 

UPDATE: AlphaImageLoader filter applied directly to the img may override the Alpha filter. As for removing a filter have you tried filter:none; ?

Yes, programmically target IE6 and below with conditional comments.

<!--[if lt IE 7]>
<style>a:hover{filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=75);}</style>
<![endif]-->

Also scripts like IE7-js will handle PNG transparency for you without cluttering up your CSS with non-standard code.

<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript"></script>
<![endif]-->
SpliFF
Sorry I am not interested in IE 6 - I am trying to get this working in IE7 and IE8 when using the '-ms-filter' or 'filter' css properties.
cbp
The solution works for ie7 too. just change the condition to lt IE8 and the script to ie8.js
SpliFF
But the problem is occurring in IE 8 even: when you apply either the 'filter' or '-ms-filter' properties in CSS, any PNG alpha transparency no longer works.
cbp
ah.. ok, I misunderstood the question. Maybe try applying an AlphaImageLoader filter directly to the image and see if it overrides the Alpha filter on the A.
SpliFF
Ah cool thanks that works
cbp
well, I also need to remove the filter in style override (think .loading or .active css classes), filter:none does not work :(
skrat
+6  A: 

Just embellishing SpliFF's answer, I could fix this problem by adding the following jQuery to my page:

$(function() {
    if (jQuery.browser.msie)
        $('img[src$=.png]').each(function() {
            this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+this.src+",sizingMethod='scale')";
            });
});

This will apply the AlphaImageLoader too all PNGs in the page.

cbp
This little script (and a few span tags around the images I'd like to fade) is a wonder and a treasure for those who have to wrestle with the MSIE abomination.
Brian