margin-top in a nested div

前端 未结 6 1821
失恋的感觉
失恋的感觉 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:38

    This is how margins work.. the margin is the space between the next element with a margin / padding / similar. It is not necessarily defined as its parent element. Consult the spec.

    Here are some things you can do as a workaround

    Use Padding Instead

    This just means instead of using margin-top: 10px; you use padding-top: 10px;. This is not suitable for every occasion.

    Weird Hack I Discovered

    I doubt I discovered this initially, but the other day I solved the problem like this. I had a

提交回复
热议问题