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

标签 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>

最佳答案

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

Demo

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

关于html - CSS:如何水平居中和垂直居中对齐文本内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16805606/

相关文章:

javascript - 如何映射对象数组并更改样式?

html - 在表格单元格中垂直对齐每个 block

html - CSS:如何垂直对齐对象,以便增加标签的字体大小不会丢失所有内容?

html - XSLT 是否值得投入时间,是否有任何实际的替代方案?

javascript - 使用JS变量(ubernewb)进行音频暂停/播放

html - 网格布局 2 列垂直尺寸相互独立

javascript - .toggle() 无限且不确定地切换类名

javascript - 使用 For 循环 JS 分配变量

html - 如何在溢出后给当前div添加滚动?

css - 垂直对齐图像叠加中的文本