CSS: Margin Collapse

Man lernt ja nicht aus. Ein ehemaliger Kollege hat nicht gerade auf einen Artikel auf scriptjunkie{} aufmerksam gemacht in dem es um vertical margins collapse geht.

Hat man diesen HTML Code:

<div>
 This is the first div.
</div>
<div>
 This is the second div.
</div>

Und so was als CSS:

div
{
	margin-top: 50px;
	margin-bottom: 20px;
}

Ist der Absand zwishcen den beiden divs 50px und nicht 70px.

When vertical margins are adjacent, the CSS specification says that the margins must collapse into a single margin, and the width of the single margin will be the maximum of adjoining margin widths.

Possibly related posts (automatically generated)