How to vertically center text in div

This question already has an answer here:

  • How to vertically center a div for all browsers? 41 answers

  • Have you tried

    <div style="text-align: center;">
    

    Works for horizontal center.

    Try this for vertically centered.

    or

    CSS

    body, html, #wrapper {
    width: 100%;
    height: 100%
    }
    
    #wrapper {
    display: table
    }
    
    #main {
    display: table-cell;
    vertical-align: middle;
    text-align:center
    }
    

    HTML

    <div id="wrapper">
    <div id="main">
    Content goes here
    </div>
    </div>
    

    Hope this helps. Do leave a feed back.


    尝试这个:

    replace margin-top: 40%; to following css
    
    display: table-cell;
    vertical-align: middle;
    text-align:center;
    
    链接地址: http://www.djcxy.com/p/41510.html

    上一篇: 如何居中DIV弹出窗口?

    下一篇: 如何在div中垂直居中文本