CSS to vertically align text to middle of div

前端 未结 6 2008
清酒与你
清酒与你 2021-02-13 14:11

What is the correct way to force text in a div to vertically align to the middle? I have found a couple \'tricks\', but I need something that works with a single line and multip

6条回答
  •  时光取名叫无心
    2021-02-13 14:22

    Try this, it will work.

        
    Your Text Here

    Css Class

        #outer {
            height: 100%;
            overflow: hidden;
            position: relative;
            width: 100%;
            display: table;
            position: static;
        }
    
        div.greenBorder {
            background-color: #39B9FF;
            text-align: center;
            color: white;
        }
    
        #middle[id] {
            display: table-cell;
            position: static;
            vertical-align: middle;
            width: 100%;
        }
    
        #middle {
            position: absolute;
            top: 50%;
        }
    

提交回复
热议问题