centre element vertically


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.