views:

85

answers:

4

I am using this CSS for background opacity of a <div>:

background: rgba(255, 255, 255, 0.3);

It’s working fine in Firefox, but not in IE 8. How do I make it work?

+2  A: 

Create a 1x1 png pixel whith same opacity applied as background.

EDIT : to fall back with IE6 you can specify kgbd chunk for the png, this is a color which will replace transparency if not supported. You can fix it with gimp eg.

MatTheCat
Yup. `rgba()` colour values aren’t supported in IE 8.
Paul D. Waite
+1  A: 

You use css to change the opacity. To cope with IE you'd need something like:

.opaque {
    opacity : 0.3;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
    filter: alpha(opacity=30);
}

But the only problem with this is that it means anything inside the container will also be 0.3 opacity. Thus you'll have to change your HTML to have another container, not inside the transparent one, that holds your content.

Otherwise the png technique, would work. Except you'd need a fix for IE6, which in itself could cause problems.

laurencek
haha typical case of one browser not acting like the rest, and each version of that browser not acting like other versions of the **same** browser... only Microsoft could achieve this quite so successfully...
ClarkeyBoy
@ClarkeyBoy: “typical case of... each version of that browser not acting like other versions of the same browser” Well, if every version of a browser acted the same, there wouldn’t be a point in having different versions, would there?
Paul D. Waite
@Paul D. Waite: There are many, many features that browsers offer besides how they render content. Deviating from the spec isn't (or shouldn't be) a feature.
Bobby Jack
@Paul D. Waite: Ok I see your point, but what I mean is that different versions of IE act **so** different that I find myself having to create a different stylesheet for each version... I have different stylesheets for IE6, 7 and 8... yet I only have one stylesheet for all of FF/Chrome/Opera/Safari. @Bobby Jack: Seconded...
ClarkeyBoy
@Bobby: Sure, but IE 8 doesn’t deviate from the standards more than IE 7 or IE 6, surely?
Paul D. Waite
@ClarkeyBoy: sure. I find my IE 8 stylesheet is a heck of a lot simpler than my IE 6 stylesheet though. IE is the oddest of browsers, but it’s slowly aligning with the others. Firefox didn’t support `rgba()` until version 3, and Opera didn’t support it until version 10.
Paul D. Waite
ok I'll give them that they are slowly getting better. But surely if they had've stuck to the standards from the start then they would have saved both themselves and web developers a hell of a lot of time, resources and money... (not sure about resources - but certainly the other two...)
ClarkeyBoy
@ClarkeyBoy: But that assumes the standards were there at the start. Standards and implementations do a [delicate dance](http://lists.w3.org/Archives/Public/public-html/2010Jan/0107.html) (see also [Mark Pilgrim’s expansion on this point](http://diveintohtml5.org/past.html)). What’s easy for one browser to implement may not be easy for another. The CSS 3 color module first went to “last call” in 2002. Firefox didn’t implement `rgba()` for another 6 years after that, whereas Safari had it much earlier. The standards process is not Perfect Standard -> Perfect Implementations -> Everyone’s Haapy.
Paul D. Waite
(And just for clarity, the CSS 3 colour module was subsequently pulled back from “last call” when the definition of “last call” changed, and only returned to it in mid-2008.)
Paul D. Waite
+1  A: 

the transparent png image will not work in IE 6-, alternatives are:

with CSS:

.transparent {

    /* works for IE 5+. */
    filter:alpha(opacity=30); 

    /* works for IE 8. */
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";

    /* works for old school versions of the Mozilla browsers like Netscape Navigator. */
    -moz-opacity:0.3; 

    /* This is for old versions of Safari (1.x) with KHTML rendering engine */
    -khtml-opacity: 0.3; 

    /* This is the "most important" one because it's the current standard in CSS. This will work in most versions of Firefox, Safari, and Opera. */  
    opacity: 0.3; 
}

or just do it with jQuery:

// a crossbrowser solution
$(document).ready(function(){ 
    $(".transparent").css('opacity','.3');
});
Thomasz
A: 

to simulate RGBA and HSLA background in IE, you can use a gradient filter, with the same start and end color ( alpha channel is the first pair in the value of HEX )

background: rgba(255, 255, 255, 0.3); /* browsers */
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#4cffffff', endColorstr='#4cffffff'); /* IE */
diablero13