Recently, while working on an ecommerce site. I ran into a problem where everytime an element had its opacity set to anything less than 100 percent, the text on the page would seem to dim on Firefox for Mac. Upon closer inspection, I realized the text wasn’t changing opacity or color, but rather, the aliasing itself seemed to be changing - similar to what you see in Photoshop if you change the aliasing of text from strong to crisp.
After pulling my hair out for a couple of hours, I hit mailing lists in search of an answer. Luckily Thomas Fuchs of Script.aculo.us fame was listening:
“I think you’re experiencing a firefox bug here, that is it switches from the Mac OS X-native text antialiasing to it’s own antialiasing when the opacity less then 100% — which produces inferior results. Plus, the rendering engine, in some situations, seems to extend this to other, non-related elements.”
Armed with this new knowledge, I was able to refine my searches, and dig up corroborating evidence this was indeed the case. Finding an answer to the problem, however, proved to be more elusive.
It turns out the answer is - there isn’t an answer. There are a couple of things you can try, but there doesn’t seem to be any one silver bullet.
- If you’re setting opacity in your stylesheet like:
div#translucent {Try switching it to use Effect.Opacity from the Script.aculo.us library instead:
filter:alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
}<code> new Effect.Opacity('translucent',{duration: 0, to: .6}); </code>Or vice versa - if you’re using Effect.Opacity, try switching to the stylesheet method. - It seems that the problem is more widespread when the translucent element is absolutely positioned. If possible try to get the element in place by other means.
- Finally, try moving the element to different places in the DOM, and positioning it with css.
None of these techniques are guaranteed to work. Using the above methods, I was able to lessen the effect, but not completely remove it. I was finally able to work around the issue by using a translucent png image for my background, but this was only possible because the element was turned on and off with simple hide and show methods. If you want to use something fancier like Effect.Appear or Effect.Fade from script.aculo.us, you’re could run into this problem again. (because those effects rely on Effect.Opacity).
While this post doesn’t directly relate to the prototype library, I hope it saves some of you a few fruitless hous of debugging. Now go forth, and translute*
* To make translucent - yes, I made it up.
It’s your lucky day, I ran into this today and found a fix in about 3 minutes (oh yeah I got mega lucky). I am posting the fix on my blog later today but I’ll post it here too and post a link to this on my site as well for reference.
The solution is to do this.
body {
opacity: 0.99999;
-moz-opacity: 0.99999;
-khtml-opacity: 0.99999;
filter: alpha(opacity=99);
}
Consequently my coworker found this bug on the peepcode site and we came up with this and it works like a charm.
Wow. I can confirm that what Kevin said IS the silver bullet. Thank you so much, I’ve been struggling with this for 2 days now.
This is a great solution for 99% of the problems out there. Keep in mind, however, it can thin out text even in places where you don’t want that to happen, and it can reduce contrast in your site, making content hard to read. I’m struggling with these side effects on this very site.
Thanks for the find though Kevin, it’s definitely a life-saver! (usually)
Kevin,
Nice find. However, I’m running into issues with embedded objects (namely Flash). My Flash objects have disappeared when the body tag is set in this manner.
The solution might be to assign opacity rules at a lower level, say all <p> tags on the page. Unfortunately, this isn’t as quick of a fix (or nearly as silver-bullet-y).
Not a bad start, though…
Scott,
You’re correct. Firefox has a bug where any elements that have an opacity set, cannot intersect with a flash object or the flash object will disappear. You can try some of the suggestions I have in the article. Whenever using flash though, I try not to set opacity anywhere, and get around the deficiency by using png files.
Setting the opacity to .9999 works in many cases; however, it causes sIFR to disappear, at least in my tests, so it can’t be used on any element (like body) which could contain sIFR.
Wow after all of my searching I finally found this post and it completely helped me fix the same issue.
Thanks ALL =)
Just like to say thanks for all working on this - if only we had a work around that would play nice with embedded flash objects.
Damn Mozilla - are they aware of this bug?
[...] Fortunately, this can be fixed with a simple stylesheet trick, as seen in the first comment here. You can apparently combat the aliasing problem by assigning a 99% opacity to objects (although it’ll break your SIFR and other elements, so be careful what you apply it to). « Learned Today: King And Vietnam. Categories [...]
[...] 추가 Simpltry의 Firefox for Mac and Opacity Problem에 따르면 opacity가 변할때 실제 opacity가 변하는게 아닌 osx의 firefox가 텍스트 안티알리아싱 엔진을 osx - firefox사이에서 왔다갔다 하면서 생기는 안티알리아싱의 변화라고한다. [...]
Man, I’ve been struggling with this problem for months- across all my sites- for a while I thought it was bad coding on my part- but seeing that it doesn’t happen in Safari or Opera- and then finding this forum, I’ve got a little confidence back- Now to the point of this-
The .99 opacity trick “works” but it doesn’t fix anything. It just makes the problem unnoticeable. If you have any small text, then you’ll end up with thinner/less readable text. Why doesn’t Firefox just fix this so I can stop stressing!?
I found a bug ticket for this problem in the Bugzilla page- doesn’t look like there is any movement on it. Maybe if people post to it they’ll get it fixed!
https://bugzilla.mozilla.org/show_bug.cgi?id=420020
@Kevin Miller: Thanks a lot, that’s great!
Kevins trick is good but it you a using any mootools type javascript effects it makes them less smooth and a bit jerky (in FF mac only).
shame I thought it was solved.