views:

162

answers:

3

Can I control the visibility of some div in my website and make to become see-through using CSS only? In flash it's done through controlling what is called Alfa so I'm wondering if such a thing exist in CSS!

Edition 001

Can I control the opacity of the div's background only? So the text in the div wouldn't be effected?

+3  A: 

You can use opacity in CSS

.transparent_class {
 opacity: 0.5;
}

I think there are some problems with opacity in Internet Explorer so here is example how to change transparency in IE:

.opaque1 { // for all other browsers
 opacity: .5;
}

.opaque2 { // for IE5-7
 filter: alpha(opacity=50);
}

.opaque3 { // for IE8
 -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}

HTH

Pavel Nikolov
Yes, but IE6, and perhaps 7, will barf on this. In those browsers, you don't set opacity without some javascript library or filter hack.
Squeegy
This is one way, but it has the downside that all descendants inherit the same opacity. If you only want the background-color to be see-through, you can use `background-color: rgba(12, 34, 56, 0.5)` where the last number is the alpha channels value (0-1).
nikc
Will this>>background-color: rgba(12, 34, 56, 0.5)<< be supported in all browsers?
MAK
@MAK, no. See this: http://css-tricks.com/rgba-browser-support/
Tatu Ulmanen
+1  A: 

http://www.quirksmode.org/css/opacity.html

.opaque1 {  // for all other browsers
    opacity: .5;
}

.opaque2 {  // for IE5-7
    filter: alpha(opacity=50);
}

.opaque3 {  // for IE8
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
Squeegy
Can I control the opacity of the background only? So the text in the div wouldn't be effected?
MAK
In decent browsers, as `nikc` said, you can use rgba colors: `background-color: rgba(255,0,0,0.5) //transulcent red`. But again, IE will barf on this.This page has a snippet of another filter hack that will work in IE though: http://css-tricks.com/rgba-browser-support/But really you may have better luck with a semi transparent PNG image set to the color and opacity you want.
Squeegy
transparent PNG! Very interesting trick!Would it work with all browsers?
MAK
@MAK - in all but IE6 (at least, not without a hack - see DDBelatedPNG)
K Prime
+2  A: 

Another way to make only the background transparent is by using a transparent png as background-image, and then use this jQuery fix for the special snowflake IE. This works in all browsers as far as I know.

kemp