0

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?

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
  • possible duplicate of [Cross browser div center alignment using CSS](http://stackoverflow.com/questions/2935404/cross-browser-div-center-alignment-using-css) – BalusC Jul 24 '10 at 01:39

2 Answers2

4

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
  • 18,608
  • 15
  • 75
  • 116
0

I know this is an old question, but for anyone who stumbles across this in search of a solution to a similar question, I've written a jQuery plugin that can center any block element very easily. This is not to promote my own project, I honestly just want to help out and contribute where I can. There's a link and demo here.

rtheunissen
  • 7,347
  • 5
  • 34
  • 65