我有两个div,在外部div我给了.1的不透明度,然后我有一个内部div不应该继承父容器不透明属性。但为了避免这种情况,我所做的是添加一个z-index属性(对子元素更高),但它不起作用。如何避免子div继承其父容器的不透明属性:为什么z-index不适用于不透明?
<!DOCTYPE HTMl>
<html>
<head>
<style type="text/css">
#outer{width:500px;height:400px;background:#000000;border:1px solid red;opacity:.1;z-index:1}
#inner{width:450px;height:350px;background:#ffffff;margin: 0 auto;margin-top:20px;z-index:2}
</style>
</head>
<body>
<div id="outer">
<div id="inner">
</div>
</div>
</body>
</html>
您不能使用z-index来定位父/子之间的相对位置。 Google搜索[“opacity inheritance css”](https://www.google.com/webhp?rlz=1C1TSNP_enUS471US471&sourceid=chrome-instant&ie=UTF-8#hl=zh-CN&rlz=1C1TSNP_enUS471US471&output=search&sclient=psy-ab&q=opacity% 20inheritance%20css&oq =&gs_l =&pbx = 1&fp = e90d0913f918c708&bav = on.2,or.r_gc.r_pw.r_cp.r_qf。,cf.osb&biw = 1178&bih = 614)为您提供了一堆关于您的问题的优秀文章。 – jfriend00 2012-07-22 04:10:43
你也可以查看这个http://stackoverflow.com/questions/5138006/no-opacity-on-div-inside-a-div-with-opacity-css – 2012-07-22 04:22:38