This question already has an answer here: 這個問題在這裏已有答案: ide
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. 即便使用margin-top
屬性,我找不到任何方法在div
垂直居中文本。 How can I do this? 我怎樣才能作到這一點? 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; }