I have a div that contains an image and a p tag (seen below). I want to align the image in the middle of the div vertically depending on how many lines the paragraph is. Vertical-align doesn’t work. I am using JavaScript right now to figure out how much to add to margin-top, but would rather use CSS. Any ideas?
<div>
<img>
<p>Multi-line</p>
</div>
Try setting the
line-heightattribute of thepelement to the height of the image, eg:Edit: Just realised I misread the question and missed the fact the
pwould be multi-line. One option to try is removing theimgelement altogether and setting it as thebackground-imageof thepinstead, with abackground-positionofleft, center. Something like: