+ -
当前位置:首页 → 问答吧 → DIV设置margin:0px auto;不居中的原因?

DIV设置margin:0px auto;不居中的原因?

时间:2011-03-17

来源:互联网

页面头部如果加了:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">,DIV居然就会不居中了,(IE,FF都不居中).
如果头部文件是 <html xmlns="http://www.w3.org/1999/xhtml">,就显示居中,
为什么DIV属性不继承Body的text-align:center;属性了?

下面是CSS样式:
body{margin:0px; text-align:center; font-family:"宋体"; font-size:12px; color:#555555; background:url(images/top_BG.jpg) repeat-x; background-color:#FFF;}
#container{width:1002; position:relative; margin:0px auto; text-align:left;}

[ 本帖最后由 bobp2000 于 2011-3-17 13:03 编辑 ]

作者: bobp2000   发布时间: 2011-03-17

#container{width:1002; position:relative; margin:0px auto; text-align:left;}

这里不会有问题吧

作者: tinshee   发布时间: 2011-03-17

width:1002;   你这个1002没单位啊哥们,你写个PX就搞定了。。

作者: kele5240   发布时间: 2011-03-17