views:

114

answers:

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.

A: 

This is untested but try:

margin-top: auto;
margin-bottom: auto;
Darrell Brogdon
That's equivalent to `margin-top: 0; margin-bottom: 0;`
eyelidlessness
Yeah, after testing I found it didn't work.
Darrell Brogdon
+3  A: 

Give this CSS-only solution a try.

Josh Stodola