CSS:如何对齐水平居中和垂直居中的文本内容?

时间:2013-05-29 04:38:34

标签: html css vertical-alignment alignment

如何将div中的文本内容与水平居中和垂直居中对齐?

   <div style="height: 300px;">
     <p>Envision various details for your big day with help from our photo catalog, which features images filtered by category. See actual works from suppliers to help you make decisions.</p>
   </div>

1 个答案:

答案 0 :(得分:2)

您需要将display: table-cell;vertical-align: middle;属性与text-align: center;一起使用,以使文本垂直和水平居中对齐

Demo

div {
    border: 1px solid #f00;
    display: table-cell;
    text-align: center;
    vertical-align: middle
}