子元素的margin-top影响父元素原因和解决办法
生活随笔
收集整理的這篇文章主要介紹了
子元素的margin-top影响父元素原因和解决办法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這個問題會出現在所有瀏覽器當中,原因是css2.1盒子模型中規定,
In this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin. 所有毗鄰的兩個或更多盒元素的margin將會合并為一個margin共享之。毗鄰的定義為:同級或者嵌套的盒元素,并且它們之間沒有非空內容、Padding或Border分隔。
解決辦法
給父元素加個padding-top:1px;?
轉載于:https://www.cnblogs.com/lijinwen/p/5838473.html
總結
以上是生活随笔為你收集整理的子元素的margin-top影响父元素原因和解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转:MFC中创建多线程
- 下一篇: Retrofit 2使用要点梳理:小白进