Skip to content

Instantly share code, notes, and snippets.

@ReeMii
Created September 24, 2013 13:40
Show Gist options
  • Save ReeMii/6684875 to your computer and use it in GitHub Desktop.
Save ReeMii/6684875 to your computer and use it in GitHub Desktop.
Vertical Align Middle
$(window).resize(function() {
$(".container > img").each(function() {
var cHeight = $(this).parent(".container").height(),
cWidth = $(this).parent(".container").width(),
iHeight = $(this).height(),
iWidth = $(this).width();
$(this).css({
top: 0.5*(cHeight - iHeight),
left: 0.5*(cWidth - iWidth)
});
});
}).resize();
/*
.container {
text-align: center;
position: relative;
}
.container > img {
position: absolute;
z-index: 2;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment