CSS中的盒子模型詳解

來源:互聯網
上載者:User

標籤:模型

 

很多人對盒子模型搞暈頭了,下面通過一個簡單的代碼來分析盒子模型的結構!

為了方便方便觀看!在第一個div中畫了一個表格,並將其尺寸設定成與div內容大小一樣!且設定body的margin和padding的屬性都為0px;

本例子採用行內CSS樣式!

代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>盒子模型</title></head><body style="margin:0px; padding:0px;"><div style="; height::auto">  <div style="width:900px; height:100px; background-color:#021; color:#FFF; padding:25px; margin:25px;border: 50px solid #0CF; ">    <table width="900px" height="100px" border="1" cellspacing="0" cellpadding="0" bordercolor="#FF0000">      <tr >        <td style="text-align:center; font-size:36px;">Javalittleman</td>      </tr>    </table>    <div style="; height:120px; float:left; background-color:#063; border-color:#039;">  <div style="; height:120px;float:left; background-color:#123;">  <div style="; height:120px;float:left; background-color:#111;"></body></html>
把尺規開啟!

大家發現了什麼沒有?

650) this.width=650;" title="QQ20141119131234" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px" border="0" alt="QQ20141119131234" src="http://s3.51cto.com/wyfs02/M01/53/9B/wKiom1RsL_-Qg5RZAAcruYhOIBE389.jpg" "1370" height="736" />

 

顯示效果:

 

650) this.width=650;" title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/53/99/wKioL1RsMHfQ91EbAAHEWUkXA7A254.jpg" "1370" height="741" />

 

其它設定的table是固定不變的,也就是說內容大小都不會改變的,改變的只是位置!

border:是邊框,向外擴張,並可以為其添加顏色屬性;

margin:是向外擴張,沒有顏色屬性,所以我們看到擴張後的顏色是外部的顏色,在本例子中是無色的!

padding:是向內填充的,沒有顏色屬性,顯示的顏色是內部內容設定的顏色!

CSS中的盒子模型詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.