CSS in detail about margin does not overlap the text code

Source: Internet
Author: User

margin overlap

Excerpt from the css2.1 specification Chinese version

In CSS, adjacent margin of two or more boxes (possibly but not necessarily brothers) is combined into a margin. Margin is called overlapping in this way (collapse)
, the resulting union margin is called the overlapping margin.

Calculation rules for margin overlap

Excerpt from the css2.1 specification Chinese version

When two or more margin merges, the resulting margin width is the maximum value in the consolidated margin width. As for negative margin, the maximum value of the absolute value of the negative adjacent margin is subtracted from the maximum of the positive adjacent margin. If there is no positive margin, subtract the maximum of the absolute value of the adjacent margin with 0

What is the adjacent margin

Excerpt from the css2.1 specification Chinese version
Two margin is adjacent, if and only if:

    • is a block-level box within a stream, in the same block formatting context.

    • No row box (line box), no voids, no padding and no border to separate them (note, therefore some 0 height box)

    • are vertical adjacent box edges (vertically-adjacent box edges), which is from one of the following pairs:
      1. The top margin of a box and its first stream is the child's top margin
      2. A box of bottom Margin and the top margin
      3 of the sibling (its next in-flow following sibling) in the next stream. The last stream is the child's bottom margin and its parent's bottom margin, If the parent's height is calculated as ' auto '
      4. A box of top and bottom margin, the box does not establish a new block formatting context and the computed value of Min-height is 0,height calculated as 0 or ' auto ', and there is no stream child

    • If any part of a margin is adjacent to another margin, it is considered to be adjacent to that margin and is a merge (collapsed) margin.

      Analyze each condition in detail 1. All belong to the stream block-level box, in the same block formatting context.

      What is an in-stream element? If an element is floating, absolutely positioned, or is a root element, then it is an out-of-flow element. If an element is not out of the flow, it is called an in-stream element. The
      Stream inner block-level box is a box generated by block-level elements in the stream.

      Conclusion 1: The box margin of the root element does not overlap (cause: The root element is a block-level box, but not an element within the flow).

      For a

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.