下面的代码(也可以在JS Fiddle上作为演示使用)没有将文本放置在中间,正如我理想中的那样。div
即使使用margin-top
属性,我也找不到任何方法可以使文本垂直居中。我怎样才能做到这一点?
<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;
}
I know it’s totally stupid and you normally really shouldn’t use tables when not creating tables, but:
Table cells can align multiple lines of text vertically centered and even do this by default. So a solution which works quite fine could be something like this:
HTML:
CSS (make the table item always fit to the box div):
See here: http://www.cssdesk.com/LzpeV