margin的塌陷现象
生活随笔
收集整理的這篇文章主要介紹了
margin的塌陷现象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、標準文檔流中,margin不疊加,以較大的為準。
案例代碼如下:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>margin的塌陷現象</title> 5 <style type="text/css"> 6 .div1{ 7 width: 100px; 8 height: 100px; 9 background-color: red; 10 margin-bottom: 10px; 11 } 12 .div2{ 13 width: 100px; 14 height: 100px; 15 background-color: yellow; 16 margin-top: 30px; 17 } 18 </style> 19 </head> 20 <body> 21 <div class="div1"></div> 22 <div class="div2"></div> 23 </body> 24 </html>效果如下:
2、如果對兩個盒子都設置了浮動屬性,并且他們都位于水平位置。margin會疊加:
代碼如下:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>margin的塌陷現象</title> 5 <style type="text/css"> 6 .div1{ 7 width: 100px; 8 height: 100px; 9 background-color: red; 10 float: left; 11 margin-right: 10px; 12 } 13 .div2{ 14 width: 100px; 15 height: 100px; 16 background-color: yellow; 17 float: left; 18 margin-left: 30px; 19 } 20 </style> 21 </head> 22 <body> 23 <div class="div1"></div> 24 <div class="div2"></div> 25 </body> 26 </html>效果圖如下:
如果不在標準流,比如盒子都浮動了,那么兩個盒子之間是沒有塌陷問題的。
轉載于:https://www.cnblogs.com/myunYao/p/8952224.html
總結
以上是生活随笔為你收集整理的margin的塌陷现象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51Nod 1007 正整数分组(01背
- 下一篇: linux查看与修改交换内存配置(解决z