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/