Deep understanding and application of position

Source: Internet
Author: User
Position commonly known as positioning, the main value and function as follows:

Position is not complex, confusing application is difficult to understand, the main rules are as follows:

Out of document Flow

In addition to the static property value, other values leave the element out of the document flow (float also causes the element to detach from the document stream).

Effect on Width and height

1) The reference point of the absolute is the closest parent element (position to absolute, relative, fixed element), the fixed Reference Point browser window, and the relative reference point as the element's normal position.

2) When the element itself value is inherit

A) when the width and height values of the parent element are numeric, the element inherits the full height of the parent element and is referenced with the nearest reference point.

. wrap{            position:relative;            width:500px;            height:300px;            border:1px solid red;        }        . cont{            Background:gray;            width:150px;            Overflow:hidden;        }        . txt{            Background:yellow;            width:230px;            Height:inherit;        }        . banner{            Background:pink;            width:50%;            Height:inherit;        }        . txt-cont{            Position:absolute;            Background:darkblue;            Width:inherit;            Color:white;        }
                    Cont                            txtxtxt                                    txt-cont                                                        Banner                    

b) When the width and height values of the parent element are percentages, the width, height * Percentage of the reference point element is calculated.

. wrap{            position:relative;            width:500px;            height:300px;            border:1px solid red;        }        . cont{            Background:gray;            width:150px;            Overflow:hidden;        }        . txt{            Background:yellow;            width:50%;            Height:inherit;        }        . banner{            Background:pink;            width:50%;            Height:inherit;        }        . txt-cont{            Position:absolute;            Background:darkblue;            Width:inherit;            Color:white;        }
                    Cont                            txt                                    txt-cont                                                        Banner                    

3) When the element itself is a percentage (50%)

In this case, regardless of whether the width and height of the parent element are numeric or percentages do not affect the element itself, the element itself is calculated as a reference.

. wrap{            position:relative;            width:500px;            height:300px;            border:1px solid red;        }        . cont{            Background:gray;            width:150px;            Overflow:hidden;        }        . txt{            Background:yellow;            width:50%;            Height:inherit;        }        . banner{            Background:pink;            width:50%;            Height:inherit;        }        . txt-cont{            Position:absolute;            Background:darkblue;            width:100%;            Color:white;        }
                    Cont                            txt                                    txt-cont                                                        Banner                    

The default location after positioning

The default position after the fixed and absolute properties is in place, just immediately following the normal document flow element will be on top, covered by the positioned element.

He had no solution to Z-index's relationship.

A detailed introduction to Z-index is shown in the following section, where only the position is created in addition to the static value (Z-index is not auto).

1) When the Z-index is numeric, a cascading context is created, and the child elements cascade order as a reference.

2) When Z-index is auto, cascading contexts are not created and the stacking order is consistent with z-index:0.

  • 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.