CSS to vertically align text to middle of div

前端 未结 6 1988
清酒与你
清酒与你 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:19

    I've made a quick example for you, using display: table-cell property on the parent div.

    CSS:
        .outer {
        width: 500px;
        height: 500px;
        display: table-cell;
        background-color: red;
        vertical-align: middle;
    }
    
    .inner {
        display: block;
        width: 300px;
        height: 200px;
        margin: 0px auto;
        background-color: yellow;
    }
    

    HTML:

    http://jsfiddle.net/aKT42/

提交回复
热议问题