HTML元素都可以看做一個裝了東西的盒子,
1,盒子裏面的內容到盒子邊框之間的距離即填充(padding),
2,盒子本身有邊框(border)
3,盒子邊框外和其他盒子之間的距離是邊界(margin)
看到一個關於盒模型的圖示,覺得寫的很好,分享給大家一下。
下面我們來看一個盒模型的實例,
比方說我們要設計這樣一個網頁,如下圖:
<div id="nav"></div>
<div id="content"></div>
<div id="footer"></div>
<body>
<div id="header"></div>
<div id="nav"></div>
<div id="content"></div>
<div id="footer"></div>
</body>
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
margin: 0px auto;
height: auto;
width: 760px;
border: 1px solid #006633;
}
height: 100px;
width: 760px;
background-image: url(headPic.gif);
background-repeat: no-repeat;
margin:0px 0px 3px 0px;
}
height: 25px;
width: 760px;
font-size: 14px;
list-style-type: none;
}
#nav li {
float:left;
}
#nav li a{
color:#000000;
text-decoration:none;
padding-top:4px;
display:block;
width:97px;
height:22px;
text-align:center;
background-color: #009966;
margin-left:2px;
}
#nav li a:hover{
background-color:#006633;
color:#FFFFFF;
}
#content {
height:auto;
width: 740px;
line-height: 1.5em;
padding: 10px;
}
#content p {
text-indent: 2em;
}
#content h3 {
font-size: 16px;
margin: 10px;
height: 50px;
width: 740px;
line-height: 2em;
text-align: center;
background-color: #009966;
padding: 10px;
}