给多行文字设置垂直居中

效果图:

给多行文字设置垂直居中_第1张图片

页面代码:

<div class="left">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sem erat,
        egestas quis luctus ut, rhoncus vitae risus. Integer venenatis libero sit amet sapien dictum,
        quis bibendum mi volutpat. Cras pretium quam quis magna facilisis, eget feugiat nisi lacinia.p>
div>

首先给父级元素设置display:table;

.left{
    width: 630px;
    background: #ff0000;
    height: 300px;
    float: left;
    display: table;
}

然后给子元素设置display:table-cell; vertical-align:middle;

.left p{
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

你可能感兴趣的:(给多行文字设置垂直居中)