user1517081
user1517081

Reputation: 965

How to correctly vertical align image+text inside table cell

I need to vertical-align:top both 'Some text' and 'Other text'. The following is not working for me, only the second cell is aligned correctly. I don't understand what the problem is.

<style>
    td {
      vertical-align:top;
    }
</style>

<table>    
    <tr>
        <td><img src="icon.png"/> Some text </td>
        <td> Other text </td>
    </tr>
</table>   

Upvotes: 8

Views: 20367

Answers (1)

joshnh
joshnh

Reputation: 8704

Rather than using:

td {
    vertical-align: top;
}

Use:

td {
    vertical-align: baseline;
}
td img {
    vertical-align: top;
}

Upvotes: 16

Related Questions