1

how to set the zindex value of the child div's greater than parent div. where parent zindex differs.

2 Answers 2

2

Positioning contexts nest. A descendant div's z-index only has to be higher than other descendant divs in the same positioned ancestor in order for it to appear on top. A positioned child will appear on top of the positioned parent even if it has a lower z-index.

At no time is it necessary for an element to know about its positioned-ancestor's z-index.

Sign up to request clarification or add additional context in comments.

Comments

1

If you really want to know how to do this...

node.style.zIndex = node.parentNode.style.zIndex + 1;

node is the child div.

2 Comments

This will only work if parentNode sets its z-index in a style attribute.
incase what would be if i'm unable to access the parent node's div

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.