2013-05-29 58 views
0

我如何對齊div水平居中和垂直居中的文本內容?CSS:如何對齊以水平爲中心和垂直居中的文本內容?

<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> 
+0

看到這個鏈接你可以得到的東西..... http://stackoverflow.com/questions/9073594/vertically-and-horizo​​ntally-centering-container-和容器內容 http://stackoverflow.com/questions/9430831/vertically-and-horizo​​ntally-centering-text-within-a-div –

+0

瞭解vertical-align或「How(Not)垂直居中內容「http://phrogz.net/CSS/vertical-align/index.html – Nish

+0

大家好,從@ mr.alien回答讓它工作。謝謝! – iamnards

回答

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 
} 
+0

謝謝@ mr.alien!太棒了! :) – iamnards

+0

@iamnards;)你歡迎 –