Margin collapse phenomenon (that is, the solution to set margin-top in the inner layer is invalid)

Source: Internet
Author: User

There are two div with nested relationship, if the padding value of the parent element of the outer div is 0, then the value of Margin-top or Margin-bottom of the inner Sub Div will be transferred to the outer parent Div, that is, the Magrin collapse phenomenon.

    Workaround:

1. Add: Overflow:hidden on the parent element div;

2. Change the outer margin of the margin-top to the padding-top inner margin;

3. Parent Element Div produces margin overlapping edges with border that are not 0 padding or width not 0 and style is not none; the parent element adds padding-top:1px;

4. Let the parent element generate a block formating context, the following properties can be implemented
* Float:left/right
* Position:absolute
* Display:inline-block/table-cell (or other table type)
* Overflow:hidden/auto
Parent-level div plus: position:absolute;

Margin collapse phenomenon (that is, the solution to set margin-top in the inner layer is invalid)

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.