margin-top in a nested div

前端 未结 6 1820
失恋的感觉
失恋的感觉 2020-12-04 21:52

I have a problem with the margin-top in a nested div -- when I apply margin-top to the nested div, the margin is applied to the parent div inst

6条回答
  •  时光说笑
    2020-12-04 22:35

    "Collapsing margins" is your problem. Here you could understand what is and why it's still alive: http://www.sitepoint.com/web-foundations/collapsing-margins/

    I read across the web to look for a decent solution, and finally I found this article: http://www.seifi.org/css/understanding-taming-collapsing-margins-in-css.html

    In short you have a bunch of methods to resolve your problem:

    1) border in parent div (could be transparent)

    2) padding in parent div

    3) overflow: auto

    4) float: left

    You should follow the link because it explains in detail all the solutions.

提交回复
热议问题