tags:

views:

147

answers:

5

I have a div tag contain text:

<div id="XXX" class="xxx">
    fffsdssfdf
</div>

And the CSS like this:

.xxx{
opacity :50;
}

But the Text doesn't opacity.

+1  A: 

It depends on your browser. Opacity works for Firefox and Safari. (use "opacity:" instead of "opacity :"). You also have to fix the opacity value, because this value must be defined between 0 and 1.

For IE, try :

filter: alpha(opacity=85)
Philippe
Is there any way to do cross browser opacity?
Ted Wong
+2  A: 

Opacity is a CSS 3 propery. It's expressed from 0 - 1.0. So 50% opacity would be like this:

.xxx {
    opacity: 0.5;
}

It's also not supported in many browsers (IE 6 & IE 7), but there are some workarounds. Examples here: http://webdesign.about.com/od/css3/a/aa121306.htm

Keltex
+1  A: 

For those browsers supporting RGBA:

<!DOCTYPE html>

<html>
<head>
<style type="text/css">
h1 {
  color: rgba(255, 0, 0, .5/* opacity */);
}
</style>
</head>
<body>

<h1>RED</h1>

</body>
</html>
Ionuț G. Stan
+2  A: 

For cross browser opacity, you want:

{ 
    -moz-opacity:.50; 
    filter:alpha(opacity=50); 
    opacity:.50; 
}
Andrew Bullock
+2  A: 

Cross-browser Solution:

Courtesy of http://davidwalsh.name/css-opacity

.show-50 { 
  -moz-opacity:.50; 
  filter:alpha(opacity=50); 
  opacity:.50; 
}

For inclusion of IE8

Courtesy of Laith Bade

.show-50 { 
  -moz-opacity:.50; 
  -ms-filter:"alpha(opacity=50)"; 
  filter:alpha(opacity=50); 
  opacity:.50; 
}
Jonathan Sampson