z-index是否继承父级z-index? [英] z-index inherits parents z-index , or not?

查看:519
本文介绍了z-index是否继承父级z-index?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个绝对div. div A上的一项将显示div B(点击+一些JavaScript代码).我希望B的Zindex高于A.(我希望B高于A)-

I have two absolute divs. One item on div A will show div B (on click + some javascript code). I want to have a higher Zindex on B than on A. (I want B above A)-

此项具有自己的zindex(低于div A zindex). 我比zindex是孩子的父母继承的,但似乎不是.

This item has its own zindex (lower than div A zindex). I thouhgt than zindex was inheritated by childrens from parents , but it seems it doesn't.

问题是...?如何为我的项目"获取计算出的" zindex

The question is ...? How can I get the 'computed' zindex for my 'item'

推荐答案

否,它不是继承的.您可以在 MDN文章中看到它.

No, it isn't inherited. You can see it in MDN article.

但是,请注意,z-index相对于堆叠上下文设置z位置.并且定位元素的非auto z-index将创建一个堆栈上下文.

However, be aware that z-index sets the z-position relatively to the stacking context. And a positioned element with non auto z-index will create an stacking context.

这意味着如果您有

<div id="a">
    <div id="b"></div>
</div>
<div id="c"></div>

#a, #b, #c { position: absolute; top: 0 }
#a { z-index: 1; }
#b { z-index: 1000000; }
#c { z-index: 2; }

然后,即使#b具有更高的z-index#c也将与#b重叠.

Then, #c will overlap #b, even though #b has higher z-index.

因此,z-index在技术上不是继承的,但是祖先的z-index确实会影响z位置.

Therefore, z-index is not technically inherited, but z-index of ancestors does affect z-position.

我建议阅读没有人告诉您什么Z索引

这篇关于z-index是否继承父级z-index?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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