標籤:模型
很多人對盒子模型搞暈頭了,下面通過一個簡單的代碼來分析盒子模型的結構!
為了方便方便觀看!在第一個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中的盒子模型詳解