zoukankan      html  css  js  c++  java
  • div+css实现Firefox和IE6兼容的垂直居中

    Firefox中使用display: table-cell; vertical-align: middle;可以实现div垂直居中,而IE6中则需要借助IE6中css的特点实现垂直居中。为了实现Firefox和IE6兼容的垂直居中,还需要 借助于!important标记。Firefox支持!important标记,而IE6忽略!important标记,因此可以使用! important标记区别Firefox和IE6。

    [示例代码]

    <html>
        <body>
            <div style="display: table-cell; vertical-align: middle; height: 200px; border: 1px solid red;">
                <p>垂直居中,Firefox only</p>
                <p>垂直居中,Firefox only</p>
                <p>垂直居中,Firefox only</p>
            </div>
            <div style="border: 1px solid red; height: 200px; position: relative;">
                 <div style="position: absolute; top: 50%;">
                     <div style="position: relative; top: -50%;">
                         <p>垂直居中,IE6 only</p>
                         <p>垂直居中,IE6 only</p>
                         <p>垂直居中,IE6 only</p>
                     </div>
                 </div>
            </div>
            <div style="border: 1px solid red; height: 200px; position: relative; display: table-cell; vertical-align: middle;">
                 <div style="position: static !important; position: absolute; top: 50%;">
                     <div style="position: relative; top: -50%;">
                         <p>垂直居中,Firefox IE6 only</p>
                         <p>垂直居中,Firefox IE6 only</p>
                         <p>垂直居中,Firefox IE6 only</p>
                     </div>
                 </div>
            </div>
        </body>
    </html>

    [div+css的浏览器兼容问题]

    水平居中,Firefox使用margin-left: auto; margin-right: auto; IE6 使用text-align: center;
    垂直居中,Firefox中使用display: table-cell; vertical-align: middle;可以实现div垂直居中,而IE6中则需要借助IE6中css的特点实现垂直居中。
    !important标记,Firefox支持!important标记,IE6忽略!important标记
  • 相关阅读:
    《网络是怎样连接的》读书笔记一
    移植mplayer到开发板
    解决ubuntu安装ssh服务无法打开解析包问题
    嵌入式软件工程师面经
    c语言-数组、指针面试题
    Linux命令- echo、grep 、重定向、1>&2、2>&1的介绍
    回调函数的作用
    数据结构-单链表回环函数判断
    算法-一步步教你如何用c语言实现堆排序(非递归)
    算法-快速排序
  • 原文地址:https://www.cnblogs.com/trendline/p/1223248.html
Copyright © 2011-2022 走看看