border、margin、padding属性的区别

可以先看下这个视频教程:http://my.tv.sohu.com/us/97014746/64226777.shtml

本文参考:http://www.cnblogs.com/chinhr/archive/2008/06/20/1227084.html

              http://www.cnblogs.com/time-is-life/archive/2008/01/21/1046817.html

             http://www.cnblogs.com/tianyue3107/archive/2009/04/22/1441358.html

1.Margin

   用来设置页面中一个元素所占空间的边缘到相邻元素之间的距离.

2.Padding

   用来设置元素内容到元素边界的距离。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .list1
        {
            580px;
            height:50px;
            background-color:Red;
            margin-bottom:100px;
            padding-left:10px;
            padding-right:10px;
            padding-top:10px;
        }
        .list2
        {
            600px;
            height:60px;
            background-color:Green;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div1" class="list1">
     Div1这里 580px;需要用600px-10px-10px( padding-left; padding-right),才能DIV2的600px保存一致。<br/>
     Div1这里 height:60px;需要用60px-10px(减除 padding-top的内边距距离),才能高度和DIV2的60ox保持一致。
    </div>
     <div id="div2" class="list2">
     我的 600px;  height:30px;
    </div>
    </form>
</body>
</html>

  

原文地址:https://www.cnblogs.com/51net/p/3676769.html