DIV的透明背景

4
当我使用这段代码时,为什么内部DIV也变成透明的了?我的计划是让文字可见并具有透明背景。我需要将内部div浮动到透明div上吗?
您可以在此处查看实时演示:http://jsfiddle.net/pBAf5/ HTML
<div class="openinghours floatRight">
  <div class="content">My test goes here</div>
</div>

CSS

.openinghours { 
  height: 70px;
  width: 300px;
  padding: 10px;
  font-size: 0.85em;
  background-color: #f6f6f6; 
  border: solid 1px #c7c7c7;
  margin-right: 20px;
  margin-top: 5px;
  opacity: .5;
  filter: alpha(opacity=50);
  border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px; 
}
2个回答

0

使用rgba或透明的png,或将内部文本移动到不透明度div的兄弟节点中。


2
RGBA: http://css-tricks.com/rgba-browser-support/,对于兄弟节点,您需要使用绝对定位。 - Jarrett Widman

0

不透明度属性不仅会影响父级 div,还会影响子级 div。要实现所需的效果,您需要在父级 div 上使用透明背景。可以通过使用 RGBA 作为父级 div 的背景颜色(不完全跨浏览器)或使用透明 PNG 作为父级 div 的背景图像来实现。


但是我无法通过CSS选择我的背景图像的透明度级别? - Steven
我认为你可以通过纯CSS实现完全跨浏览器的解决方案,这对我很有效。http://akshar.co.in/?p=57 - Eastern Monk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接