Created
August 9, 2012 20:01
-
-
Save jshaw/3307577 to your computer and use it in GitHub Desktop.
Vertically aligning images in a div (Fix for IE8 & 9)
This file contains 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
// WORKS FF, Chrome, Safari, IE 8 & 9 etc... | |
$('.extra-content .graphics img').load(function() { | |
$(this).css('marginTop', $(this).parents('.graphics').height() / 2 - $(this).height() / 2 ); | |
}); | |
// DOESN'T WORK IE8 & 9 | |
// With multiple images on a page this script seems unable to compute the marginTop var. | |
// However placing it directly into the CSS method works as shown above. | |
$('.extra-content .graphics img').load(function() { | |
var marginTop = $(this).parents('.graphics').height() / 2 - $(this).height() / 2; | |
$(this).css('marginTop', marginTop); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment