您的位置:首页 > Web前端 > CSS

CSS:margin属性备忘

2010-03-03 10:22 330 查看
参考资料:http://www.blueidea.com/tech/web/2007/4546.asp,由浅入深漫谈margin属性 - 网页制作 - 蓝色理想

直接上代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>aaa</title>
<style type="text/css">
html { }
body { margin:0px; }
</style>
</head>
<body>
<div id="div1" style="width:500px; height:500px;background:#fff000;margin:20px 0px -300px 0px;">
<!--这里的top 10px标记为a,下面的top 12px标记为b,影响div1的是ab两值有负数取和、无负数取最大值,left和top理论上一样,未测试-->
<div style="width:200px; height:200px; background:#ccc;margin:20px 10px 0px 10px;" id="div1_1"></div>
<div style="width:50px; height:50px; background:#ff0000;margin:10px 10px 0px 10px;" id="div1_2"></div>
</div>
<div id="div2" style="width:500px;height:100px;background:#fffff0;margin:100px 0px 0px 0px;"></div>
<!--margin to 100受div1的影响,div1的bottom margin值为-300,高500-300为200,div2应该出现在div1的高200的地方

,因为top100,所以再往下移动100,所以bottom和right是对其他非置换元素有影响,right未做测试-->
<!--置换元素(replaced element)主要是指img,input,textarea,select,object等这类默认就有CSS格式化外表范围

的元素-->
</body>
</html>

显示效果如下:

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