Set Z-index invalidation when position is fixed

Source: Internet
Author: User

As a fake front-end, the following bugs appear when you debug a page.
On the left side of the menu fixed to fix, the level two menu can not set effective z-index, resulting in the menu hidden under the page elements, obviously page elements of the Z-index is 1, but regardless of the menu Z-index set to how large, are not useful.

Looked up the information, the original Google browser in the setting position:fixed, will trigger the element to create a new cascade context, and as a whole in the parent Cascade context comparison. As the above DOM structure, when the Position:fixed property is set to B, it triggers the creation of a new cascade context, and its parent cascade context becomes a, so B can only cascade comparisons within a. This is the "from the father principle" that everybody listens to.

So all elements are compared in root, but only within the parent element after being fixed, and the parent element is not set Z-index, so cannot be compared.

So the solution is to set the Z-index for the parent element, which is generally set to 0.
Excerpt two points:
1. Z-index only works if the position is set to relative,absolute,fixed.
2. Z-index "from the Father principle". When you find out how much of the z-index is useless, see if the parent element is set to a valid Z-index, and of course don't forget to see if you set the position first.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.