The question about margin

the distance between the two div is 10px. is there any difference in the following two ways, or which one is better?

1, div1 {margin:10px 0}

2, div1 {margin:5px 0} div2 {margin:5px 0}

Mar.18,2021

when two margin are adjacent, it can cause problems with merging, leaving only the largest margin, unless you use a border to separate or float. So there is no good or bad, only whether it is suitable for a scene


I only say the second way of writing, the second way of writing will cause a problem: outer margin overlap , there are two prerequisites for the occurrence of outer margin overlap: first, it only occurs on block elements (excluding float, absolute, inline-block elements); second, it only occurs in the vertical direction. So your second way of writing doesn't hold water.


there is a difference. The second kind of distribution is relatively uniform, and there is no difference between good and bad. Look at the scene.

Menu