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>

 

相关文章:

  • 2021-10-10
  • 2021-11-03
  • 2021-08-31
  • 2022-12-23
  • 2022-01-08
  • 2021-11-13
猜你喜欢
  • 2021-12-01
  • 2021-08-05
  • 2022-02-13
  • 2021-09-08
  • 2021-09-28
相关资源
相似解决方案