Skip to content

Instantly share code, notes, and snippets.

@unviva
Last active April 22, 2017 08:24
Show Gist options
  • Save unviva/a2121ab6e27d308cfd267fd3babfadb7 to your computer and use it in GitHub Desktop.
Save unviva/a2121ab6e27d308cfd267fd3babfadb7 to your computer and use it in GitHub Desktop.
Vertically and horizontally align a div within window
// .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