views:

99

answers:

2

Is there a way of vertical aligning text and an image in a list?

e.g.

<li>Some text here <img src="image.jpg" alt="" /></li>

The text doesn't align in the middle of the side of the image, it appears at the bottom then the image is next to it. I need the text to be in the center point between the image on the side.

What's the best way of doing it? I know having a image inside a list isn't valid HTML (AFAIK).

Thanks :)

A: 

If the text doesn't wrap, you can set line-height same as the height of image:

li { line-height: 42px }

And yes, having img inside li is perfectly valid, since img is (by default) inline element while li is block level element.

jholster
+2  A: 

You can use

li img {vertical-align: middle;}

if text fits one line

Voyta
+1 More elegant than mine.
jholster