Why does the set margin-top attribute not work? margin-top does not work.

Source: Internet
Author: User

Why does the set margin-top attribute not work? margin-top does not work.

Why does the margin-top attribute not work:
Suggestion: writing code as much as possible can effectively improve learning efficiency and depth.
Sometimes you may encounter a strange phenomenon. Although there are no syntax errors, the configured margin-top attribute does not work, the following describes the cause and solution of this problem based on the code example.
Cause 1:
The outer margin merged with the margin-top attribute is invalid. The code example is as follows:

<! DOCTYPE html> 

From the running of the code above, we can see that the margin-top set for the second div does not take effect. What works is the margin-bottom set for the first div. Here there is a rule, that is, the height of the merged outer margin is equal to the larger of the height of the outer margin. In this case, pay special attention to the setting of the outer Margin Size.
Cause 2:
The child element and the parent element may also cause the top and outer margins of the child element to become invalid. The code example is as follows:

<! DOCTYPE html> 

Solution:
It can be avoided if the parent object has borders and padding in the corresponding outer margin direction, or the overflow attribute value is set to hidden.
In the IE 6 browser, the outer margin is not merged.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 4638.

For more information, see: http://www.softwhy.com/divcss/

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.