CSS:margin属性备忘

参考资料: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>

 

显示效果如下:

CSS:margin属性

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值