垂直對齊div內的文本[重複] - Vertically align text within a div [duplicate]

問題:

This question already has answers here : 這個問題在這裏已經有了答案
Closed 7 years ago . 7年前關閉。

The code below (also available as a demo on JS Fiddle ) does not position the text in the middle, as I ideally would like it to.下面的代碼(也可作爲JS Fiddle 上的演示提供)沒有將文本放在中間,這是我理想中想要的。 I cannot find any way to vertically centre text in a div , even using the margin-top attribute.我找不到任何方法在div垂直居中文本,即使使用margin-top屬性也是如此。 How can I do this?我怎樣才能做到這一點?

<div id="column-content">
    <img src="http://i.stack.imgur.com/12qzO.png">
    <strong>1234</strong>
    yet another text content that should be centered vertically
</div>
#column-content {
    display: inline-block;
    border: 1px solid red;
    position:relative;
}
    
#column-content strong {
    color: #592102;
    font-size: 18px;
}

img {
    margin-top:-7px;
    vertical-align: middle;        
}

解決方案:

參考一: https://stackoom.com/question/coBD
參考二: Vertically align text within a div [duplicate]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章