If your main container height is fluid, your only reliable choice is to use JavaScript (of course, the discussion point here, of course, the discussion one). In JavaScript, you must first find the height of the container, then the height of the window and adjust the top offset accordingly. Here's how you do it in jQuery:
$(function() { $(window).resize(function() { var top = $(window).height() / 2 - $('#content').height() / 2; top = top < 0 ? 0 : top; $('#content').css('top', top); }); $(window).resize(); });
And CSS to make it work:
#content { position: absolute; width: 960px; margin: 0 auto; }
And HTML:
... <body> <div id="#content">Content here</div> </body> </html>
This is still pretty simple and will work if the user has JavaScript enabled.
Tatu Ulmanen Dec 15 '09 at 19:46 2009-12-15 19:46
source share