tags:

views:

147

answers:

4

I have a hyperlink in display: block mode and it's placed in a table cell (td). The hyperlink text is showing at the top of the cell. Want it in the middle for all common browsers.

I am using a hover effect where the background color of the cell changes. The text position looks odd.

A: 
<table>
<tr>
<td style="vertical-align : middle;">
<a href="#" style="display : block"></a>
</td>
</tr>
</table>

Is this what you are looking for? Notice the "vertical-align : middle" in the cell style.

nlaq
That won't work. The link is taking the whole cell space because it's a block. So there's nothing to display in the middle. there's no 'air' to move things around.Try this test:<table><tr><td style="vertical-align : middle; border: 1px solid red"><a href="#" style="display : block;height: 100px; border: 1px solid green">test</a></td></tr></table>
Tony_Henrich
A: 

I used the solution from this page with some minor css modifications:

http://apptools.com/examples/tdcolor.php

Tony_Henrich
A: 

You could try defining line-height for your a element

td a {line-height: 2em; /* other css */}

This should force the text to be vertically centred. Bearing in mind that, should the text wrap to a second line, you might end up with an undesired end-result.

David Thomas