Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Created July 2, 2014 23:32
Show Gist options
  • Save mikeselander/93fc49c292a62f78dd7e to your computer and use it in GitHub Desktop.
Save mikeselander/93fc49c292a62f78dd7e to your computer and use it in GitHub Desktop.
Maintain an exact size & margin between an unknown number of images within a parent div - useful for situations where a user can add multiple (unknown) number of logos to a box (generally footer)
function adjust_header_banner(){
var footer = $('.footer');
count = 0;
totalWidth = 0;
// Calculate distance between partner images
$('.partners img').each(function() {
totalWidth += $(this).width();
count += 1;
});
var margin = ( ( footer.width() - totalWidth ) / ( count - 1 ) )
$(".partners img").css({
'margin-left' : ( margin / 2 ),
'margin-right' : ( margin / 2 ),
'max-width' : ( ( 100 / count ) - 1 ) + '%'
});
}
$(document).ready(adjust_header_banner);
$(window).load(adjust_header_banner);
$(window).resize(adjust_header_banner);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment