+ -
当前位置:首页 → 问答吧 → 求解下2个width,margin:-75px的作用

求解下2个width,margin:-75px的作用

时间:2011-07-11

来源:互联网


<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8" /> <style> #position{position:absolute;top:50%;left:50%;width:50%;width:150px;height:40px;margin:-20px 0 0 -75px;padding:0 10px;background:#eee;line-height:2.4;} </style> </head> <body> <div id="position">水平垂直居中的对象</div> </body> </html>
 提示:您可以先修改部分代码再运行
在网上看到这么一段代码,求解下2个width,margin:-75px的作用

作者: wd513517   发布时间: 2011-07-11

top跟left是高和宽的一半.
定位后负边距居中的办法

作者: cycloned   发布时间: 2011-07-11

width:50%;width:150px;这个?

作者: wd513517   发布时间: 2011-07-11

width:50%;完全是冗余代码没有任何作用.

position:absolute;
top:50%;left:50%;
width:150px;height:40px;

margin:-20px 0 0 -75px;

作者: cycloned   发布时间: 2011-07-11

热门下载

更多