I have long noticed that when two block elements are put next to each other, their margin stacks on each other. Something like this:
Both <div>
s have margin: 1em
, but when margin1
's margin-bottom
collides with margin2
's margin-top
, both margin just stack on each other. See on here: http://jsfiddle.net/39XmC/
What I was expecting was something like this:
Both <div>
s actually give spaces on each margin and doesn't stack on each other's margins.
I know that this can be fixed by floating or overflowing the element. My question:
- Why does this happen [theoretically]? Isn't margin not supposed to stack?
- Is this the default behavior on browsers? Because I remember working on a project that doesn't have this behavior.