CSS實現文本垂直置中

來源:互聯網
上載者:User

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>

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.