Opacity CSS that works for all browsers?

偶尔善良 提交于 2019-12-18 12:21:51

问题


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

Erik


回答1:


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;
}



回答2:


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/




回答3:


Although CSS 3 introduces the new opacity feature for transparency, it does not support all browsers. This is a CSS trick for transparency in all browsers

.transparent_class {  
 filter: alpha(opacity=50);  
 -moz-opacity: 0.5;  
 -khtml-opacity: 0.5;  
  opacity: 0.5;
}    


来源:https://stackoverflow.com/questions/5640815/opacity-css-that-works-for-all-browsers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!