Answer the question
In order to leave comments, you need to log in
How to dynamically change the width of a DIV?
Tell me how you can dynamically change the width of a DIV depending on how many DIVs with a fixed width are nested in it? For example: the width of the main div is 8500 - 10 DIVs of 800px each are nested in it, plus 50 for padding. Nested DIVs line up horizontally. The bottom line is that there would be no extra scrolling, for example, when nested DIVs are not 10 but 5
Answer the question
In order to leave comments, you need to log in
Well, there aren't many options here. Wrap/replace everything with a table, or javascript set the width of the parent. You can also try with
#parent{white-space:nowrap;} .child{display:inline-block;}
$(function(){
var w = 0;
$(".child").each(function(){
w += $(this).width();
});
$("#parent").width(w);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question