When I want to place some (logically meaningful) div inside a (logical) container div with some space apart as below,
There is no hard-and-fast rule on this, because it all depends on context, and in complex designs, you usually have no choice but to use one or the other to get the desired result.
That said, you should try to group logically related rules together. For instance, when you have two HTML elements on a website that serve a similiar purpose, e.g. your outer If, however, you are placing more than one element into the outer edit: In your second situation, I usually combine Probably looks complicated, but works regardless of margin collapsing and has served me very well.margin
on the inner padding
and margin
, like this:.outer {
padding: 10px 15px 10px 5px
}
.inner {
margin-left: 10px
}