Once in a while when two elements with the following criteria
- has only content (no padding and no border)
- has vertical margins applied to it
When they touch each other the margin collapse to the larger of the two margins.
In the below example, we have two boxes which satisfies the above criteria.
- Both the boxes have 20px vertical margins. They should have
40pxmargins between them.
- Due to the vertical margin collapse, they have only
20pxmargin between them as shown in the below pen.
There are multiple solutions to solve this problem.
- You can apply border to one of the element
- You can apply padding to one of the element