文字在div中垂直居中

這個方法只能將單行文本置中。只須要簡單地把 line-height 設置爲那個對象的 height 值就可使文本居中了。瀏覽器

<div id="content"> Content here</div> code

#content { height: 100px; line-height: 100px; }對象

優勢:方法

適用於全部瀏覽器
無足夠空間時不會被截斷

缺點:di

只對文本有效(塊級元素無效)
多行時,斷詞比較糟糕
相關文章
相關標籤/搜索