现在的位置: 首页 > 综合 > 正文

Firefox下的居中问题

2012年04月26日 ⁄ 综合 ⁄ 共 463字 ⁄ 字号 评论关闭
IE下使用text-align:center就可以实现所有元素的居中效果
在Body的text-align为center的情况下
我们在Body中插入下面的HTML代码
<div style="background-color:#006699; width:800px;">文字内容</div>
在IE中,通过背景的颜色差异我们可以明显看到这些元素以居中方式表现出来;
然而在Firefox中,Div是以默认方式居左的,文字则是居中也就是说在Firefox中text-align是真正的只是Text控制而已
要想达到div也居中的话需要给div添加一个margin:auto
最终效果是
<div style="background-color:#006699; width:800px;margin:auto">文字内容</div>

还有另外一种方案
就是添加<center>
<center>
<div style="background-color:#006699; width:800px;">文字内容</div>
</center>

同样也可以解决居中问题

抱歉!评论已关闭.