<body onclick="bodyclick()" leftMargin=200 topMargin=120 rightMargin=200>
<div id="mainDiv" style="height:auto;padding-left:5px;padding-top:5px;background-color:#99FF00">
<input type="text" value="zheshi">
</div>
</body>
padding是内边距,也就是div里的第一个元素排版相对于div排版的边界位置。
效果:
[img]http://dl2.iteye.com/upload/attachment/0089/0632/82b9b9c7-04b4-3b47-9b49-04da6b51591d.jpg[/img]
对于margin,则是div相对于其外元素排版的相对偏移。在上段代码里,div是包含于body里的,而body里设置了leftMargin,也就是说文档展示会相对浏览器左侧偏移200px之后,又会增加div的margin距离
<div id="mainDiv" style="height:auto;padding-left:5px;padding-top:5px;background-color:#99FF00">
<input type="text" value="zheshi">
</div>
</body>
padding是内边距,也就是div里的第一个元素排版相对于div排版的边界位置。
效果:
[img]http://dl2.iteye.com/upload/attachment/0089/0632/82b9b9c7-04b4-3b47-9b49-04da6b51591d.jpg[/img]
对于margin,则是div相对于其外元素排版的相对偏移。在上段代码里,div是包含于body里的,而body里设置了leftMargin,也就是说文档展示会相对浏览器左侧偏移200px之后,又会增加div的margin距离