Why does margin-top not act on the parent element and the margin-top element?

Source: Internet
Author: User

Why does margin-top not act on the parent element and the margin-top element?

Why does margin-top not act on the parent element:
The basic usage of the margin-top attribute is simple, but it is to set the top margin of an object. See the following code example:

<! DOCTYPE html> 

The above Code sets the top margin of the div to 50px. Everything runs well and there is no problem. Let's take a look at the next code:

<! DOCTYPE html> 

The original intention of the above Code is to make the top of the child element 50 PX away from the parent element, but in fact it does not achieve the expected effect, but it is close to the parent element at the top of the child element, in addition, margin-top seems to have been transferred to the parent element, so that the parent element produces the top margin. This is actually a typical problem of outer margin merging, but not all browsers will produce this situation. Generally, this phenomenon occurs in standard browsers, IE6 and IE7 do not merge the margins in this status. Conditions for the combination of top and outer margins:
1. There is no border between the top margin of the parent element and the top margin of the child element.
2. There is no non-empty content between the top margin of the parent element and the top margin of the child element.
3. There is no padding between the top margin of the parent element and the top margin of the child element.
3. The positioning attributes (except static and relative), overflow (except visible), and display: inline-block are not set in the parent element and child element.
4. The parent element or resource is not floating.
Note: The preceding conditions must be met. The solution to this problem is also very simple, as long as the above situation is damaged.

Original address: http://www.51texiao.cn/div_cssjiaocheng/2015/0501/506.html

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.