views:

867

answers:

5

I keep seeing 60-80% opacity on tables on websites. They look really cool, but I'm not sure why they are doing it. Is it Javascript, or is it an image? How do I change the opacity of a table?

+1  A: 

Opacity can be specified in CSS, but it's not supported by all browsers (specifically older IE)

Nik
+12  A: 

You can do it in CSS, but it requires a little hacking to get it to work cross-browser.

selector {
    filter: alpha(opacity=50); /* internet explorer */
    opacity: 0.5;           /* fx, safari, opera, chrome */
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=50)"; /*IE8*/
}
tj111
For IE8 in standard mode you have to write:-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
Rafael
Thanks, wasn't aware of that. Of course MS made it even more difficult. Added it to the post.
tj111
+1  A: 

IE uses the syntax filter:alpha(opacity=80), where a lower value makes the element more transparent, while Mozilla uses -moz-opacity:0.8 where a lower value has the same effect on transparency. The same things goes for the CSS3 valid syntax opacity:0.8;

So these are the three CSS properties that you need.

filter:alpha(opacity=80); //IE

opacity: 0.8; //CSS3

-moz-opacity:0.8; //Mozilla

Mike737
+1  A: 

You can also create a 1x1 pixel 32 bit PNG image which is for example a black square with the opacity you require. Then in your css you can do...

element
{
    background: url(/Images/Transparent.png) repeat;
}

This way you can avoid all the different hacks. You may have problems with Alpha transparency in IE6 but there are ways around this also

Nick Allen - Tungle139
A: 

It can be done both ways, I prefer an alpha transparent png file as a background. Doing an alpha on the table makes the actual contents semi-transparent as well. See the other answers for the css values.

Tracker1