CSS不透明度,如何在透明容器元素中包含不透明元素

标签 css transparency opacity

我正在使用以下 CSS 代码:

.rounded_box{
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
width:850px;
padding:15px;
background-color:#80C1FF;
margin:0 auto;
color: #0D2E47;
font-family: Arial,Helvetica,sans-serif;
opacity:0.6;
filter:alpha(opacity=60); /* For IE8 and earlier */
/* background-color:rgba(255,0,0,255);  */
}
.rounded_box h1{
  opacity:1.0;
 filter:alpha(opacity=100); /* For IE8 and earlier */ 
 }

我想让 h1 和其他元素不透明,它们在 div 中具有类 rounded_box 。但也使 h1 和其他我不想要的元素透明。

那么有什么解决办法呢?

最佳答案

.rounded_box 中的 opacity: 0.6 将应用于所有子元素(因此 .rounded_box h1。因此 h1 opacity:1.0 实际上只是父级的 100% (0.6)。

你可以做的是使用 rgba 定义 .rounded_box 的背景颜色,这不会影响 child 。

关于CSS不透明度,如何在透明容器元素中包含不透明元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8184412/

相关文章:

c# - 确定图像中是否使用了 Alpha channel

java - 如果 `set setOpaque(false);`,JWindow 上的 JPanel 不透明 - 为什么?

html - 鼠标悬停时,CSS 按钮没有响应

CSS:我可以添加缓和过渡到图像颜色变化悬停效果吗?

css - 按钮动画上的 Chrome 错误

php - CodeIgniter,表单助手 - 向元素添加类

image - 如何从 Dart Flutter 中的图像中删除周围的空白?

javascript - IE7 可以在另一个之上显示两个具有不同不透明度的 div 吗?

css - 涵盖所有主要 PC 和笔记本电脑纵横比的媒体查询

html - 为什么我的 css 没有应用?