views:

3706

answers:

5

I'm using CSS to indicate the trigger text for a jQuery slide-down section: i.e. when you hover over the trigger text the cursor changes to a pointer and the opacity of the trigger text is reduced to indicate that the text has a click action.

This works fine in Firefox and Chrome, but in IE8 the opacity doesn't change.

I've tried a variety of CSS settings without any success.

For example

HTML:

<h3 class="slidedownTrigger">This is the trigger text</h3>

CSS:

.slidedownTrigger
{
    cursor: pointer;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
    filter: alpha(opacity=75);
    -khtml-opacity: 0.75;
    -moz-opacity: 0.75;
    opacity: 0.75;
}

What's stopping IE changing the opacity? Note: I've tried this on a variety of different elements, swapping round the order of the CSS statements, and just using the IE ones on their own. I've also tried using

-ms-filter: "alpha(opacity=75)";

but with no success.

I've run out of things to try to get opacity modification working in IE8.

Any ideas?

+4  A: 

No idea if this still applies to 8, but historically: http://www.satzansatz.de/cssd/onhavinglayout.html

Azeem.Butt
Sorry but what's this link got to do with opacity?
Alistair Christie
IE doesn't apply several styles to elements that don't "have layout."
Azeem.Butt
Great! Thanks. That was the problem. The elements I was trying to adjust the opacity for (e.g. h3) didn't "have layout". Once I'd given them some, the opacity worked. All I did was add width: 100%; to the h3. Thanks for pointing me in the right direction. However, it seems mad (if not buggy) that Internet Explorer does this.
Alistair Christie
+2  A: 

Setting these (exactly like I have written) has served me when I needed it:

-moz-opacity: 0.70;
opacity:.70;
filter: alpha(opacity=70);
Gabriel McAdams
Thanks, I believe "filter: alpha(opacity=70);" is for IE <8. However, it doesn't work (for me) in IE8 (I just checked).-moz-opacity is now pretty much defunct I believe, and opacity is the standards way of doing things - so, naturally, Microsoft didn't use that way of doing things (way too easy).
Alistair Christie
A: 

This related/duplicate question has your answer I think. http://stackoverflow.com/questions/859000/opacity-in-web-pages

Jeff Martin
I saw that question - trouble is the answer: <br><br>   filter: alpha(opacity=50); /* internet explorer */<br>   opacity: 0.5; /* fx, safari, opera, chrome */<br>   -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=50)"; /*IE8*/<br><br>doesn't work for me (I just tried it again to double check). I applied it to an h3 that was black and bold. In Firefox and Chrome the opacity setting turns the heading gray, as you'd expect, but in IE8 it stays black.
Alistair Christie
oops - didn't realise you don't get to use HTML in comments - but I think you can see what I'm trying to say
Alistair Christie
if you try those styles on just a solid color div do they work? maybe there is some other CSS going on that is conflicting.
Jeff Martin
Nice one. Yes - when I do a simple div, give it a height and width and a background-color of red, with those opacity settings, it works in IE8. It comes out semi-opaque. I'm struggling to see what the problem is though. I'm not modifying the opacity of anything else in the stylesheet, so I can't think what could be conflicting with it for IE only.
Alistair Christie
Alistair Christie
have you looked at the IE8 dev tools (F12) and seen if they have anything to say?
Jeff Martin
A: 

Despite IE8's claims of full CSS2.1 support, there are -- many, many bugs -- that make such a claim questionable and I wouldn't be surprised if you've run into another of them.

Rob
A: 

You need to set Opacity first for standards-compliant browsers, then the various versions of IE. See Example:

.slidedownTrigger
{
    cursor: pointer;
    opacity: .75; /* Standards Compliant Browsers */
    filter: alpha(opacity=75); /* IE 7 and Earlier */
    /* Next 2 lines IE8 */
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=75);
}

Note that I eliminated -moz as Firefox is a Standards Compliant browser and that line is no longer necessary. Also, -khtml is depreciated, so I eliminated that style as well.

Furthermore, IE's filters will not validate to w3c standards, so if you want your page to validate, separate your standards stylesheet from your IE stylesheet by using an if IE statement like below:

<!--[if IE]>
<link rel="stylesheet" type="text/css"  href="http://www.mysite.com/css/ie.css" />
<![endif]-->

If you separate the ie quirks, your site will validate just fine.

Kevin