未知高度定宽div水平居中及垂直居中(兼容ie6及其他牛逼浏览器)

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title>css</title>
        <style type="text/css">
            * { margin:0; padding:0; list-style:none;  }
            #vertical_box {
                width:100%;
                display:table;
                border:1px red solid;
                height:400px;
                *position:relative; /*针对IE的hack*/
            }
            #vertical_box_sub {
                display: table-cell;
                vertical-align: middle;
                *position:absolute; /*针对IE的hack*/
                *top:50%;
            }
            #vertical_box_container {
                font-family:"宋体";
                border:1px green solid;
                *position:relative; /*针对IE的hack*/
                *top:-50%;
                margin:0 auto;
                width:200px;
            }
        </style>
    </head>

    <body>
        <div id="vertical_box">
            <div id="vertical_box_sub">
                <div id="vertical_box_container">
                    <p>我是居中的文字</p>
                    <p>我居中</p>
                    <p>你也居中</p>
                    <img src="" border=0 alt="\" title="">
                </div>
            </div>
        </div>
    </body>
</html>

 

posted @ 2014-08-19 11:05  浪漫小生  阅读(4155)  评论(0编辑  收藏  举报