您的位置:首页 > 其它

border、margin、padding属性的区别

2014-04-20 18:06 411 查看
可以先看下这个视频教程: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

Margin 与 Padding 的区别

1.Margin

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

2.Padding

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



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.list1
{
width:580px;
height:50px;
background-color:Red;
margin-bottom:100px;
padding-left:10px;
padding-right:10px;
padding-top:10px;
}
.list2
{
width:600px;
height:60px;
background-color:Green;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="div1" class="list1">
Div1这里 width: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">
我的 width:600px;  height:30px;
</div>
</form>
</body>
</html>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: