Item with margin-top has margin outside of containing box

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 00:25:37

Try to add padding instead. I've seen this kind of problem before. If the padding does the the same thing then try putting a container div around but #div and the h1 then add the margin. If you are just wanting to move the h1 down from the #div then padding is your best bet since it will "Push the h1 further into the #div 'box'".

This is not related to the H1 tag. This is what we call margin collapse.

You can find a post about this subject here : http://reference.sitepoint.com/css/collapsingmargins

you have several solutions :

  • use padding instead
  • add overflow: auto on your parent div
  • add transparent top border to the parent div

I was able to solve this problem by making all of my header tags (h1-h6) display: inline-block;. As inline elements with margins, they can overflow like that, but as inline blocks they behave a little more nicely with others.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!