当前位置: 代码迷 >> Web前端 >> 元素正中的几种方法
  详细解决方案

元素正中的几种方法

热度:21   发布时间:2012-11-18 10:51:22.0
元素居中的几种方法

其他浏览器不多说用margin:0 auto;即可

如需兼容到ie6,让ie处于标准模式下margin:0 auto 也可达到居中的目的

如何让ie6处于标准模式呢<!doctype> 可以搞定,如下:

<!DOCTYPE html>
当然也有其他dtd文件可以达到这一目的,可以上网搜一下。

如需兼容到更低版本

推荐两种

#continer

{

position: absolute;
  left: 50%;
  width: 800px;
  margin-left: -400px;

}

另一种用到了hack

<div style="text-align:center;">

<div style="margin:0 auto;text-align:left;width:800px;></div>

</div>

  相关解决方案