Why does this CSS margin-top style not work?

前端 未结 12 1995
醉梦人生
醉梦人生 2020-11-21 04:54

I try to add margin values on a div inside another div. All works fine except the top value, it seems to be ignored. But why?

What I expected:
<

12条回答
  •  囚心锁ツ
    2020-11-21 05:11

    Doesn't answer the "why" (has to be something w/ collapsing margin), but seems like the easiest/most logical way to do what you're trying to do would be to just add padding-top to the outer div:

    http://jsfiddle.net/hpU5d/1/

    Minor note - it shouldn't be necessary to set a div to display:block; unless there's something else in your code telling it not to be block.

提交回复
热议问题