zoukankan      html  css  js  c++  java
  • IE下margin:0 auto不居中解决方法

    正常情况下需要将div居中显示时,使用Css样式:margin:0 auto即可,但有时使用margin:0 auto后在FF、Chrome里能居中,而在IE678里不居中的现象。

    如下代码:
    <style type="text/css">
    #con{980px;martin:0 auto;}
    </style>
    <div id="con">margin: 0 auto 内容居中显示</div>

    解决方法一

    可以是对网页主体<body>声明文本居中,即body{text-align:center}
    即:
    <style type="text/css">
    body{text-align:center}
    #con{980px;martin:0 auto;}
    </style>
    <div id="con">margin: 0 auto 内容居中显示</div>

    解决方法二

    其实和解决方法一差不多,只是在要居中的div外层添加多一个div,并使其居中
    即:
    <style type="text/css">
    #con{980px;martin:0 auto;}
    </style>
    <div style=“text-align:center”><div id="con">margin: 0 auto 内容居中显示</div></div>

    解决方法三

    出现这个现象的原因在于文档的DTD声明;
    修改DTD为

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  • 相关阅读:
    异步加载技术实现瀑布流效果
    点击向下展开的下拉菜单特效
    几个个实用的PHP代码片段【自己备份】
    cache和buffer区别探讨
    windows 文本文件放到linux下使用
    制作rpm包
    mariadb在线热备份做主从
    检查目录下备份文件的脚本
    different between method and function
    mysql忘记root密码解决
  • 原文地址:https://www.cnblogs.com/liuling/p/dsafaff.html
Copyright © 2011-2022 走看看