外边距在定位元素中的情况
分类:实例代码
关于margin外边距大家应该都不会陌生。
这里只是简单介绍一下margin外边距在定位元素中应用的主意点。
代码如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <style> div { width:100px; height:100px; background:#ccc; position:absolute; } </style> </head> <body> <div></div> <div style="background:red;margin-left:20px"></div> <div style="margin-left:200px;"></div> </body> </html>
当使用绝对定位(fixed也是如此)的时候,外边距定位参考对象已经不是它相邻的元素。
当是相对定位的时候,也非定位时候一样。