What is default z-Index of
element in HTML, and how to get it using JavaScript?

前端 未结 6 2009
面向向阳花
面向向阳花 2021-02-01 15:13

So normally we can get z-Index value of a div element using, e.g:

var zindex = document.getElementById(\'id\').style.zIndex;

I am using this

6条回答
  •  囚心锁ツ
    2021-02-01 15:58

    I believe everything is z-indexed as 0. Really z-index is only valid if you set it for all the elements you care about. You can set the z-index of one div to 100000, but it won't matter if you don't set the z-index of the other element you are trying to overlap.

    So I guess what I'm trying to say is that the default z-index of the div doesn't matter, it's only computed if you set it.

    A div inside of a div doesn't have a specific z-index. Ad div inside of a div inside of the body inside of an iframe, inside of 3 more divs and 1 table, doesn't have a z-index(or a z-index that's computed.).

    I can't see that there would be any practical reason for trying to find a z-index of an item, if it's irrelevant anyways.

提交回复
热议问题