最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

css设置元素背景为透明

来源:懂视网 责编:小采 时间:2020-11-27 18:53:53
文档

css设置元素背景为透明

css设置元素背景为透明:要设置某一元素的背景为透明,在 chrome 、firefox、opera 下是这样的:[css] background-color: rgba(0, 0, 0, 0.4); rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0~1之间。在 ie 中一般是这样的:[css] background-colo
推荐度:
导读css设置元素背景为透明:要设置某一元素的背景为透明,在 chrome 、firefox、opera 下是这样的:[css] background-color: rgba(0, 0, 0, 0.4); rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0~1之间。在 ie 中一般是这样的:[css] background-colo
要设置某一元素的背景为透明,在 chrome 、firefox、opera 下是这样的:
[css]
background-color: rgba(0, 0, 0, 0.4);
rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0~1之间。

在 ie 中一般是这样的:
[css]
background-color: rgb(0, 0, 0);
filter: alpha(opacity=40);
opacity 表示透明度,它的值范围在 0~100 之间

那么如何兼容各浏览器呢?只要把它们写在一起就行了。
由于 ie 不支持 rgba,所以会忽略之。其他浏览器对于自己不支持的,一般也会忽略。
下面来个示例:
HTML 代码:

[html] 
<body> 
 <div class="non-transparent"> 
 aaaaa 
 </div> 
 </body> 
 
<div class="transparent"> 
 <div class="box"> 
 box 
 </div> 
 </div>

CSS 代码:

[css] 
.non-transparent:hover { 
 background-color: yellow; 
} 
 
.transparent { 
 position: absolute; 
 top: 0; 
 left: 0; 
 
 text-align: center; 
 
 width: 100%; 
 height: 100%; 
 
 filter: alpha(opacity=40); 
 background-color: rgb(0, 0, 0); 
 
 background-color: rgba(0, 0, 0, 0.4); 
} 
 
.box { 
 background-color: yellow; 
 width: 50%; 
 height: 50%; 
 
 position: relative; 
 left: 5%; 
 top: 10%; 
}

显示效果:

20140808174213906.png

chrome:

firefox:

20140808174213906.png

opera:

20140808174213906.png

ie8:

20140808174213906.png

另外,在 chrome、firefox、opera 中也可以这样:
opacity: 0.4;
但是这样的话,会把所有子元素的透明度也设置为同样的值,效果如下图:

20140808174213906.png

文档

css设置元素背景为透明

css设置元素背景为透明:要设置某一元素的背景为透明,在 chrome 、firefox、opera 下是这样的:[css] background-color: rgba(0, 0, 0, 0.4); rgba 中的最后一个参数 0.4 就是想要的透明度,范围在0~1之间。在 ie 中一般是这样的:[css] background-colo
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top