Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opacity CSS that works for all browsers?

Tags:

css

opacity

Can someone recommend the safest approach for giving an OPACITY VALUE to a DIV TAG using CSS?

Erik

like image 875
Erik Avatar asked Apr 12 '11 19:04

Erik


2 Answers

Straight from Css-Tricks.com (this covers everything I can think of):

.transparent_class {
  /* IE 8 */
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";

  /* IE 5-7 */
  filter: alpha(opacity=50);

  /* Netscape */
  -moz-opacity: 0.5;

  /* Safari 1.x */
  -khtml-opacity: 0.5;

  /* Good browsers */
  opacity: 0.5;
}
like image 117
Justin Niessner Avatar answered Oct 26 '22 03:10

Justin Niessner


This will work in every browser.

div {
 -khtml-opacity:.50; 
 -moz-opacity:.50; 
 -ms-filter:”alpha(opacity=50)”;
  filter:alpha(opacity=50);
  filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.5);
  opacity:.50; 
}

Or you can use jQuery and do it in a single line

$('div').css({opacity:0.5});

Check working example at http://jsfiddle.net/397jv/

like image 23
Hussein Avatar answered Oct 26 '22 05:10

Hussein