2

I have found a few techniques used for vertically aligning a DIV on the page, most of them outlined here:

http://blog.themeforest.net/tutorials/vertical-centering-with-css/

But, the project I'm working on now heavily uses Javascript on a DIV aligned in the vertical center of a page. Does anyone know a method (preferably not Javascript based) to keep the DIV vertically aligned in the center of the screen even when it's height changes via Javascript?

And also with a height: auto property if possible, so it changes with my content.

Thanks.

Seth
  • 45,033
  • 10
  • 85
  • 120
Matt
  • 1,083
  • 2
  • 10
  • 15
  • Do you want strictly CSS? This is quite easy to do with tables if you're willing to break the tables-aren't-for-layout rule. – David Pfeffer Jan 07 '10 at 21:36
  • Tables are an option I guess, and probably the best one. I'm not really anal about using tables for layout anyway, I think i'll go with them. Thanks. – Matt Jan 07 '10 at 21:52
  • http://giveupandusetables.com/ I'm usually a bit more patient than that, but at some point you just give up :) – ephemient Jan 07 '10 at 22:01

2 Answers2

3

Give this CSS-only solution a try.

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
-1

This is untested but try:

margin-top: auto;
margin-bottom: auto;
Darrell Brogdon
  • 6,843
  • 9
  • 47
  • 62