Heim > Artikel > Web-Frontend > 问个关于DIV加了z-index后的问题_html/css_WEB-ITnose
div z-index
最近遇到了个问题,望高手解答写,请先看下面的代码 img 挡住后面的元素,这不科学啊。后面的 .in 设置 position:absolute;top:0;left:0;
<style>.out{position:relative;}.out .in{position:absolute;top:0;left:0;z-index:1;font-size:30px;background-color:rgba(255,0,0,.3);color:#fff;}</style><div class="out"> <img src="http://img.china.alibaba.com/images/trade/other/091231/test1.jpg" width="100" alt="" /> <div class="in">cover</div></div><div class="out bd"> <img src="http://img.china.alibaba.com/images/trade/other/091231/test2.jpg" width="200" alt="" /> <div class="in">cover</div></div>
img 挡住后面的元素,这不科学啊。后面的 .in 设置 position:absolute;top:0;left:0;
<style>.out{position:relative;}.out .in{position:absolute;top:0;left:0;z-index:1;font-size:30px;background-color:rgba(255,0,0,.3);color:#fff;}</style><div class="out"> <img src="http://img.china.alibaba.com/images/trade/other/091231/test1.jpg" width="100" alt="" /> <div class="in">cover</div></div><div class="out bd"> <img src="http://img.china.alibaba.com/images/trade/other/091231/test2.jpg" width="200" alt="" /> <div class="in">cover</div></div>
好多分,谢谢。