HTML:
<div>
<p>
Lorem ipsum dolor sit amet.
</p>
</div>
CSS:
p {
margin-top: 20px;
}
div {
width: 400px;
height: 80px;
}
Margin means space around a box FROM ITS PARENT. right?
why my p tag doen't get top margin from div? instead from body. I mean p and div get attached together.
I know with floating we can solve this. or applying border or padding.
My question is: Is there any collapsing? what's happening?
EDIT:
Sorry guys.
I know the solution as I said. I want to know the underlying concept.
Margin applies to OUTSIDE of an element.
But Consider p tag. it is INSIDE. whatever margin we give to p tag, should only apply to its siblings. not outer elements like its parent or div.