Last active
April 22, 2017 08:24
-
-
Save unviva/a2121ab6e27d308cfd267fd3babfadb7 to your computer and use it in GitHub Desktop.
Vertically and horizontally align a div within window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .well.login-inbox {margin:0px auto; } | |
function mathVert(el) { | |
var windowHeight = $(window).height(); | |
var elheight = $(el).innerHeight(); | |
var elmath = (windowHeight / 2) - (elheight / 2); | |
return elmath; | |
} | |
function varticalCenterStuff() { | |
$('.login-box').css('margin-top', mathVert('.login-box')); | |
$('.register-box').css('margin-top', mathVert('.register-box')); | |
$('.info-box').css('margin-top', mathVert('.info-box')); | |
} | |
$(window).resize(function () { | |
varticalCenterStuff(); | |
}); | |
varticalCenterStuff(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment