My question is about this code :
* {
box-sizing: border-box;
}
body {
background: rgb(0, 212, 255);
background: linear-gradient(121deg, rgba(0, 212, 255, 1) 51%, rgba(204, 64, 180, 1) 51%);
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container {
background-color: red;
width: 80%;
height: 80%;
}
.inner-container {
width: 15%;
height: 100%;
background-color: blueviolet;
}
<div class='container'>
<div class='inner-container'>
<h1>Some text </h1>
</div>
</div>
Here is codepen.
If i remove <h1>Some text</h1>
from the inner container, everything is positioned the way i want it. As soon as i add h1
or other html tag that has default margin inner container moves down and overflows parent. I can not understand why this is happening in this case. As i understand, that default margin should be applied within the inner container and it should not cause this weird behavior.
`, it should resolve the issue. It's due to [**collapsing margins**](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing).
– Tyler Roper Jul 17 '19 at 17:12