views:

57

answers:

3

I want to set something in the middle of the screen

thanks

A: 
$(window).height();

To set anything in the middle you can use CSS.

<style>
#divCentre 
{ 
    position: absolute;
    left: 50%;
    top: 50%;
    width: 300px;
    height: 400px;
    margin-left: -150px;
    margin-top: -200px;
}
</style>
<div id="divCentre">I am at the centre</div>
rahul
That CSS will put the top left corner of the div in the middle of the page. The div will then extend right and down, looking *seriously* off-center. Maybe make the margins negative? Because that seems like it might work, but only if the thing you're centering is smaller than the page.
T.J. Crowder
Fixed the typo. Thanks @ T J Crowder
rahul
Your vertical centering approach requires that you know the height of your #divCentre element.
Dustin Laine
+3  A: 
$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document

As documented here: http://api.jquery.com/height/

Dustin Laine