Skip to content

Instantly share code, notes, and snippets.

@Niloys7
Created October 25, 2015 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Niloys7/ea54d5e7351da34d8656 to your computer and use it in GitHub Desktop.
Save Niloys7/ea54d5e7351da34d8656 to your computer and use it in GitHub Desktop.
Get Equal Width for element base on parent element
var total = 0;
$('.ClassName').each(function() {
total+= $(this).width();
total+= parseInt($(this).css('margin-left'), 0);
total+= parseInt($(this).css('margin-right'), 0);
total+= 0;
});
var num_blocks = $('.ClassName').size();
// now calculate the extra space left
var extra_space = (parseInt($('.ParentClassName').width())-total)/num_blocks;
$('.tt_tabs li').each(function() {
$(this).width($(this).width()+Math.floor(extra_space));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment