我可以从父元素覆盖z-index继承吗? [英] can I override z-index inheritance from parent element?

查看:84
本文介绍了我可以从父元素覆盖z-index继承吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用绝对位置时,是否有任何方法覆盖父元素的z-index继承。我想要2222 div在0000 div之上:

Is there any way to override z-index inheritance from parent elements when using absolute position. I want 2222 div to be on top of 0000 div:

<div style="background-color:green; z-index:10; position:relative">
     OOOO
</div>

<div style="background-color:yellow; z-index:5; position:relative">
     1111
     <div style="position:absolute; background-color:red; 
                 z-index:15; top:-8px; left:20px">
         2222
     </div>
</div>

我不能改变Z索引0000或1111 divs,我试图定位我的2222元素相对于1111元素。

I can not change z-index of 0000 or 1111 divs and I am trying to position my 2222 element relative to 1111 element.

推荐答案

我相信z-index是相对于最近的元素。因此,如果在1111div中有两个div,它们可以相对于彼此z-index',但是由于2222是1111的子项,它不能相对于0000进行z索引,并且将总是以上1111。

I believe z-index is relative to the nearest positioned element. So, if you had two divs inside the "1111" div, they could be z-index'd relative to each other, but since 2222 is a child of 1111, it cannot be z-indexed relative to 0000, and will always be above 1111.

这篇关于我可以从父元素覆盖z-index继承吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆