简体   繁体   English

没有得到正确的宽度Jquery

[英]Not getting the correct width Jquery

I have a div that is dynamically populated with other divs of various widths, and i need to get the total width of all inside divs here is some code 我有一个div,动态填充各种宽度的其他div,我需要得到所有内部div的总宽度这里是一些代码

    <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>

And here is the JS 这是JS

    <script>
   var totalWidth = 0;

   $('.box').each(function() {
      totalWidth += ($(this).outerWidth(true));
   });
   $('.inner_wrpr').css({'width': totalWidth});
   </script>

But for some reason it only gives me the right width for the box divs which are narrower then the body but anything wider then the body returns the same width as the body if you could help me with that i would appreciate it. 但由于某种原因,它只给我正确的宽度,盒子div比身体窄,但任何更宽,然后身体返回与身体相同的宽度,如果你可以帮助我,我会欣赏它。

You have added * { max-width: 100%; 你添加了{{max-width:100%; } or something like that in .box parent elements. 或类似.box父元素中的类似内容。 So it doesn't allow widths greater than body's width. 所以它不允许宽度大于主体的宽度。 Check the screenshots: 查看截图:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM