CSS认识-盒子模型(Box model)

分享下我认识的CSS 盒子模型,有不对的望各位网友提出。盒子模型是我们在网页开发中常听的到名字.它由各个不同的属性名:内容(content)、填充(padding)、边框(border)、边界(margin)这些组成一个网页种的盒子,俗称盒子模型(Box Model)。

Box Model规定了元素由内容(element content)、内边距(padding)、边框(border) 和 外边距(margin) 组成。方式有两种,第一种是W3C的标准模型,另一种是IE的传统模型】

标准 w3c 盒子模型的范围包括 marginborderpaddingcontent,并且 content 部分不包含border pading(如上图)

下面是Ie 的盒子模型

 ie 盒子模型的范围也包括 marginborderpaddingcontent,和标准 w3c 盒子模型不同的是:ie 盒子模型的 content 部分包含了 border pading。以

上面介绍了盒子模型基础知识,下面我们用代码来构建以个盒子看看

<!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>  

<div id="heade">  </heard>

<div id="content"></div>  

</body>  

</html>  

 

 

#header { 

  height: 100px; 

  width: 760px; 

  padding:2px;

  margin:0px 0px 3px 0px; 

}

#content { 

  height:auto; 

  width: 740px; 

  line-height: 1.5em; 

  padding: 10px;

  border:1px solid #ccc;

}

 上面的代码分别构建了页面头部,内容部分和页脚,分别都有宽 /高,padding与margin 形成了个盒子

 

posted @ 2016-06-25 21:38  f2eone  阅读(182)  评论(0编辑  收藏  举报