It's a very common situation: a designer tells me that some piece of text should be vertically centered, but I can't use the display:table-cell; hack because the containing element needs to have a different display property
. I also don't want to have to use any position:absolute
due to the problems that presents.
Fiddle: https://jsfiddle.net/z824m656/1/
HTML
<div class="contents-vertically-centerd">
<img src="https://blog.stackoverflow.com/images/wordpress/stackoverflow-logo-300.png" width="150"/><span>Here's some text that I want vertically centered with respect to the image</span>
</div>
CSS
div.contents-vertically-centerd { padding: 10px; border: 1px dashed #000000; }