Following is the snippet (demo on JSFiddle)
#inner {
background-color: yellow;
margin-left: 50px;
margin-bottom: 50px;
}
#outer {
background-color: red;
}
<div id="outer">
<div id="inner">
test
</div>
</div>
As can be seen in the demo, the #inner
element has a margin-bottom
.
I expected the height of #outer
will be large enough to include the outline of #inner
margin. And the output will have a red bar below the yellow bar.
However, I found the #outer
's height is not changed at all though I added the rule margin-bottom: 50px
for #inner
.
Does anyone have ideas about this? And is there a way to ensure the content area of parent is large enough to hold the outline of its child's margin?
Also, apart from giving a hack solution, it would be great if the answer can include some explanation or links to related document/article. And why is the margin rule designed like this.
Thanks!