The overlap problem that margin has encountered

Source: Internet
Author: User

Double margin

Record a little bit, because often forget

float + margin, the actual margin will change to double the set value.

The workaround is to set the element to Display:inline

It is best to understand IE's haslayout problem

margin overlap in vertical direction

Previously, it was known that adjacent two block elements overlap in the vertical direction of margin.

But the overlap between the parent element and the first child element is not considered

The code is as follows:

        <Divclass= "Wrap">            <Divclass= "One">Margin 20px</Div>            <Divclass= "both">Margin 20px</Div>        </Div>        <Divclass= "WRAP2">Margin-top 50px test Distance to wrap</Div>
. Wrap{margin:0;Background-color:lightcoral;. One {margin:20px;Background-color:LightBlue; }. the{margin:20px;Background-color:LightGreen; }}. WRAP2{Margin-top:50px;Background-color:Lightgoldenrodyellow;Height:200px; }

If wrap contains no padding or border set, the margins of the wrap block overlap with the child elements.

The effect of adding a border is as follows.

The overlap problem that margin has encountered

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.