css transparency/see-through sites
published on:December 20, 2007 / 13:04
back to overviewWhen the design of the new Internet Architects site arrived, the first thing that caught my eye was the slightly transparent background on both sections of the site. The little experience I'd had with transparency had always been positive, so I thought it would be a breeze to implement.
How it's done
<--[if gte IE5.5]> .opaque {filter:alpha(opacity=80);} <![endif]-->
.opaque {opacity:0.8; filter:alpha(opacity=80);}
The best way to make an element transparent is to use the css3 property opacity. It's one
of the first css3 properties to get decent cross-browser support. The property accepts a value between 0 and 1, where
0 is totally transparent and 1 means no transparency at all.
Of course, none of the IE browsers accept the opacity property. From IE5.5 on Microsoft has been using one of their own
filters to make elements transparent. To make IE happy, we have to include
filter:alpha(opacity=80); in our css declaration, where the opacity value lies between 0 and 100.
Again, 0 means the element will be totally transparent, 100 gives you no transparency at all.
By combining these two properties, we can achieve cross-browser transparency. For older browsers there are other tricks (using transparent pngs and such) but as they are not on my A-list of browsers I'm going to ignore them here.
Why transparency is not often seen
The most obvious issue is the lack of separation between foreground and background transparency. When an element is given an opacity, the whole element becomes transparent. Meaning not just the background, but also all texts. This has some serious consequences when it comes to the readability of the text within the transparent element. Even when the contrast between the background and foreground colors is optimal, an opacity of 0.5 will greatly reduce readability.
As long as this problem remains, it's probably best to use transparency within sites solely as a graphical enhancement. With high opacity values (anything ∼0.8 and above) the text remains readable and the effect is still visible enough to keep its charm. Of course, it's always best to double check the contrast after applying the opacity, even when using high values.
Internet Explorer problems
As IE5.5+ uses filters to accomplish the effect, this means that whenever Active X scripting (or scripting in general) is disabled the transparency won't work. The percentage of people surfing like this might be quite low but they still have to be able to use your site.
With this in mind, it's a good guideline to make sure that whenever transparency is used, the site remains fully functional without the opacity applied. Practically speaking, it's better not to put content on top of each other. Even when the content can be accessed through a transparent element, the transparency can't be guaranteed, even in modern browsers.
Firefox goes dada
And there is more. While Firefox can handle the transparency fair enough, it starts messing up the elements within.
When you play around with css properties like line-height and text-decoration, Firefox starts acting up real bad. Whenever the state of an element within a transparent container changes and certain parameters are met, the text starts jumping around, sometimes even shifting background images and surrounding borders.
As far as I know, there's no fix for this behavior, which would be a rather blocking issue for the other browsers. Luckily, there is a workaround to keep the transparency going in IE, Safari and Opera. To make it work in IE we can use conditional comments to serve IE specific css. We can simply drop the filter in there and IE has transparency. But if you like keeping a clean main stylesheet, you should have been doing this already.
As for the other browsers, we use some Mozilla legacy. Long before opacity, Mozilla used its own property called
-moz-opacity. While Firefox supports the newer (and standard) opacity property, it still accepts
-moz-opacity too. By abusing this, we can simply set the opacity for Safari and Opera and disable it again for Firefox.
<--[if gt IE5]> .opaque {filter:alpha(opacity=80);} <![endif]-->
.opaque {opacity:0.8; -moz-opacity:1;}
The inconsistencies in Firefox are only triggered under certain circumstances, so in a very controlled environment the transparency could just as well be applied. In most cases, it's better to drop the transparency in Firefox as the issues are quite irritating and rather unpredictable. It's not every day we gracefully degrade one of our favorite browsers.
Article info
contact me
If you want to send me a quick message or you have any questions, don't hold back.
articles in css issues
the archive
All my articles are neatly filed inside the archive. Search and filter your way to the articles you want:
7 comments in total
Seems like the problem is solved in FF 3 beta. Go Future !
Unless of course Firefox 3 still accepts the -moz-opacity property. It takes a while for a new version to dominate previous versions, and you can't just drop Firefox 1.5 and Firefox 2 right away :)
Just a thought. Firefox users tend to upgrade their browser faster than IE users due to the way that Firefox almost forces you to upgrade. The switch to FF3 might go smoother than expected ;)
http://www.w3counter.com/globalstats.php
6% still it seems... Quite much I think. So yeah, it'd be more acceptible to drop Safari support prior to Firefox 1.5 if you look at it like that.
Jeroen, you actually prove my point by posting that link. If you take a look at IE6 vs. IE7 stats and compare them to FF1.5 vs FF2 ... My guess is that most FF users will be using FF3 within a year.
What I'm actually interested in is the proportional difference in usage between Safari 2 and Safari 3. The stats there only say Safari 2, but I suppose it takes Safari 3 into account as well.
And agreed, I like the way more programs start to auto-check for updates. It's the only way to have people to upgrade fast. But IE7 was only available to WGA compliant Windows installations, no? That might explain the slow uptake...
I just noticed the transparancy on this page is a bit f**ked... http://www.vogue-models.co.uk
* required fields