Position: absolute and Z-index in CSS affect the hierarchy

Source: Internet
Author: User

Guidance:
1. Do not use position

In this case, each layer follows the HTML positioning rules. The left, right, top, and bottom positioning information is invalid, and the Z-index will not work because there is no Cascade.

2. Use absolute

If the Z-index attribute of two absolute positioning objects has the same value, it will be stacked according to the order they are declared in the HTML document.

2.1 Z-index not used

In this case, it is layered based on the order they are declared in the HTML document, because the default value of Z-index is 0 if not set.
001

002

003

001: located at the bottom layer
002: In the middle layer
003: Highest Level

2.2 Use Z-Index

Z-index is an integer without unit and can be negative. It is arranged according to the value size. The larger the value, the more it is in the outer layer.
001

002

003

001: In the middle layer
002: located at the highest level
003: located at the bottom layer

2.3 parent and child elements

For parent and child elements, the child element belongs to the parent element level, and the child element is above the parent layer.

001
002

003

001: In the middle layer
002: located at the highest level
003: located at the bottom layer


3. Hybrid use of absolute

For elements that do not set the position: absolute attribute, no matter how many Z-index values are set, they are all 0, but below the Z-index: 0 element in position: absolute
001

002

003

001: located at the highest level
002: In the middle layer
003: located at the bottom layer

Related Article

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.