zoukankan      html  css  js  c++  java
  • IE浏览器解决margin:0 auto;不居中办法!

    一般情况下需要将div居中显示时,使用Css样式:margin:0 auto;或者margin:0 auto 1px;即可,但有时使用margin:0 auto后在firef、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">
     

  • 相关阅读:
    文件的基本操作
    ps工作界面
    HDU 6300
    HDU 6298
    HDU 2037
    HDU 2036
    Tesseract OCR
    What is the difference between position: static,relative,absolute,fixed
    How to Call a synchronize function asynchronizly in C#
    WCF note1
  • 原文地址:https://www.cnblogs.com/hr2014/p/3855248.html
Copyright © 2011-2022 走看看