div+css網頁布局設計新開端(5)

來源:互聯網
上載者:User
下面說說內外邊距合并的問題

<html><head><style type="text/css"> #a{width:100px;height:50px;background:red;margin-bottom:20px;}#b{width:100px;height:50px;background:green} </style> <head><body> <div id="a"></div><div id="b"></div> </body></html>

a層的下外邊距是20px
下面看圖

下面把綠色的層上外邊距改為10px

<html><head><style type="text/css"> #a{width:100px;height:50px;background:red;margin-bottom:20px;}#b{width:100px;height:50px;background:green;margin-top:10px;} </style> <head><body> <div id="a"></div><div id="b"></div> </body></html>

沒任何區別

簡單地說,外邊距合并指的是,當兩個垂直外邊距相遇時,它們將形成一個外邊距。合并後的外邊距的高度等於兩個發生合并的外邊距的高度中的較大者。
在看圖


如果兩者一樣的px怎麼辦?假如都是20px

<html><head><style type="text/css"> #a{width:100px;height:50px;background:red;margin-bottom:20px;}#b{width:100px;height:50px;background:green;margin-top:20px;} </style> <head><body> <div id="a"></div><div id="b"></div> </body></html>

效果還是一樣哦

下面測試一下

<html><head><style type="text/css"> #a{width:100px;height:100px;background:red;margin-top:20px;}#b{width:50px;height:50px;background:green;margin-top:10px;} </style> <head><body> <div id="a"><div id="b"></div></div> </body></html>

ie6的顯示


Firefox的顯示

可以看出ie6是不合并的,Firefox的合并的

可能有人會好奇
這個為什麼紅色沒有貼緊上面的瀏覽框
其實沒有瀏覽器都有預設的內外邊距的

只需要

<html><head><style type="text/css"> *{margin:0;padding:0;} #a{width:100px;height:50px;background:red;margin-bottom:20px;}#b{width:100px;height:50px;background:green;margin-top:10px;} </style> <head><body> <div id="a"></div><div id="b"></div> </body></html>


有些瀏覽器可能要用

body{margin:0;padding:0;}

以上就是div+css網頁布局設計新開端(5)的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.