Why margin-top of the top div would apply to `<body>`?

后端 未结 7 1598
长情又很酷
长情又很酷 2020-12-15 21:26

Here I posted a demo http://jsfiddle.net/LxYMv/1/.

As you can see gets margin-top:10px from the top div, and therefor

7条回答
  •  借酒劲吻你
    2020-12-15 21:43

    It meants that if the child starts exactly where the parent - that has no margin - starts then the childs margin will affect it. You can use the padding property instead to get the result you want like:

    body{
        padding-top:10px;
    }
    

提交回复
热议问题