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

前端 未结 6 2016
面向向阳花
面向向阳花 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:56

    Default z-index of any element is 'auto' with exception of which has default z-index:0. 'Auto' means that element gets z-index from its parent.

    You can see this by using Developer Tools (in Chrome) or any similar tool in other browser. Also you can get this in your code by window.getComputedStyle() as others proposed here.

提交回复
热议问题