Схлопывание margin #5
by fersterin
HTML
<div class="container">
<div class="dog1">dog1</div>
<div class="dog2">dog2</div>
</div>
<!--
-->
<div class="p10"></div>
CSS
.dog1 {
margin: 10px;
margin-bottom: -10px; /* Первый маргин */
padding: 10px;
background: lightgreen;
border: 1px solid olive;
width: 65px;
}
html, body {
background: lightblue;
}
.dog2 {
margin: 10px;
margin-top: -20px; /* Второй маргин */
padding: 10px;
background: lightblue;
border: 1px solid olive;
}
.container {
border: 1px solid olive;
width: 100px;
background: #fff;
}
.p10 {
margin-top: 20px;
width: 10px;
height: 10px;
background: #fff;
border: 1px solid olive;
}
.p10:after {
content: "10px";
padding-left: 15px;
display: inline;
}