views:

34

answers:

1

Say I have a like so:

<table style="margin-left: auto; margin-right: auto;">
  <tr>
    <td>
    </td>
  </tr>
</table>

The margin-* attributes instruct the table to center itself within its parent element.

Is there a similar way to center the element vertically?

+2  A: 

This is a very often requested thing to do. There's no simple way to do vertical alignment. There's the vertical-align attribute, but it's for line-alignment of an inline element. Check out this link for different ways to do vertical-centering.

Edit: Here's another good link to get you started.

TheCloudlessSky
Haha, you were first so you get dibs. :) I'll delete mine.
attack
And I complained when they took out the `<center>` tag!
George Edison
@attack - Haha, I was just re-loading to delete mine and saw yours disappear. Cheers!
TheCloudlessSky
@George - It can be quite a pain to center but I agree with the 2nd link where `Method 3` is easier to implement.
TheCloudlessSky