Why does this CSS margin-top style not work?

前端 未结 12 1970
醉梦人生
醉梦人生 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:26

    Just for a quick fix, try wrapping your child elements into a div element like this -

    Hello world!

    Margin of inner div won't collapse due to the padding of 1px in-between outer and inner div. So logically you will have 1px extra space along with existing margin of inner div.

提交回复
热议问题