Posted By

joe-bbb on 09/10/09


Tagged

javascript width jquery center height


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

rickfu
alejandrosuch
x0nine


centre element vertically


 / Published in: jQuery
 

  1. function centre_content(){
  2. var win_height = $(window).height();
  3. var content_height = $('#content').height();
  4. $('#content').css('margin','0 auto');
  5.  
  6. if ( win_height > content_height ) {
  7. $('#content').css({
  8. top : win_height/2 - content_height/2
  9. });
  10. }
  11. else {
  12. $('#content').css({
  13. top : '10px',
  14. });
  15. }
  16. }
  17. }

Report this snippet  

You need to login to post a comment.