CSS实现文本垂直居中

CSS中实现文本的垂直居中是很容易的事情,然而想要垂直居中,这还真的有些技巧,今天在网上搜索了半天,找到了如下方法,源码实例呈现:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Universal vertical center with CSS</title>
    <style>
    #outer {height: 100px; overflow: hidden; position: relative;}
    #outer{display: table; position: static;}
    #middle {position: absolute; top: 50%;} /* for explorer only*/
    #middle{display: table-cell; vertical-align: middle; position: static;}
    #inner {position: relative; top: -50%} /* for explorer only */
    .withBorder{border:1px green solid;}
    </style>
</head>
<body>
    <div id="outer" class="withBorder">
        <div id="middle">
            <div id="inner">
            any text any height any content,
            everything is vertically centered.
            </div>
        </div>
    </div>
</body>
</html>

 

posted @ 2012-05-28 23:46  likebeta  阅读(233)  评论(0编辑  收藏  举报