user1032531
user1032531

Reputation: 26311

vertical-align:middle when multiple elements are in the parent

How do I vertically center both the img and the following text inside the td?

<td><a><img width="32" height="32" alt="txt" src="txt.png">Text</a></td>

I've experimented with vertical-align:middle; but haven't been successful.

Upvotes: 0

Views: 55

Answers (2)

KatieK
KatieK

Reputation: 13853

You need to specify vertical alignment on the elements inside the table cell. In your case:

td a, td img { vertical-align:middle; }

Or see http://jsfiddle.net/ZfP7r/1/.

Upvotes: 0

Kami
Kami

Reputation: 19437

You can achieve the desired effect by placing the text inside a span tag. Then position this span as required and add a line-height with vertical-align:middle;

This should produce the desired effect - http://jsfiddle.net/tdJ8u/23/

Upvotes: 1

Related Questions