Positioning DIV element at center of screen

Posted by iSumitG on Stack Overflow See other posts from Stack Overflow or by iSumitG
Published on 2012-03-25T17:07:13Z Indexed on 2012/03/25 17:29 UTC
Read the original article Hit count: 189

Filed under:
|
|
|

I want to position a DIV (or a TABLE) element at the center of screen irrespective of screen size. In other words, the space left on 'top' and 'bottom' should be equal and space left on 'right' and 'left' sides should be equal. How to do it?

Note: I prefer a complete CSS solution, but if is not possible without Javascript then using Javascript is also fine.

I am trying the following but it is not working:

 <body>
  <div style="top:0px; border:1px solid red;">
  <table border="1" align="center">
   <tr height="100%">
    <td height="100%" width="100%" valign="middle" align="center">
      We are launching soon!
    </td>
   </tr>
  </table>
  </div>
 </body>

Note: It is either way fine if the DIV element (or TABLE) scrolls with the website or not. Just want it to be at center when page loads.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about css