Skip to content

Instantly share code, notes, and snippets.

@uniquelau
Created July 28, 2011 13:20
Show Gist options
  • Save uniquelau/1111527 to your computer and use it in GitHub Desktop.
Save uniquelau/1111527 to your computer and use it in GitHub Desktop.
Get Parent Width, Calculate difference as Percentage
$('#nav-1 li .dropdown').each(function(){
var parent_width = (((($(this).width() - $(this).parent().width()) / '2') / $(this).parent().width()) * '100') + '';
var percent_round = Number(parent_width).toFixed(2);
$(this).css('margin-left' , '-' + (percent_round) + '%');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment