我有一個動態填充與各種寬度的其他的div一個div,我需要得到這裏所有內部的div的總寬度是一些代碼沒有得到正確的寬度Jquery的
<div class="inner_wrpr">
<div class="box>
...some content...
</box>
<div class="box>
...some content...
</box>
<div class="box>
...some content...
</box>
<div class="box>
...some content...
</box>
</div>
這裏是在JS
<script>
var totalWidth = 0;
$('.box').each(function() {
totalWidth += ($(this).outerWidth(true));
});
$('.inner_wrpr').css({'width': totalWidth});
</script>
但由於某些原因,它只是給了我爲箱體的div然後身體返回相同的寬度身體 如果你能幫助我與較窄然後身體但任何更廣泛的權利寬度我將不勝感激。
你有沒有設定* {最大寬度:100%}在CSS的地方? – mehulmpt
「.box」元素的寬度設置如何? –
爲什麼容器的寬度不適合內容,您是使用position absolute,max-width還是其他任何東西來限制容器的寬度? – adeneo