简体   繁体   English

通过JS插入DOM元素时,根据子元素调整父Div的大小

[英]Resize Parent Divs according to Child elements when inserting DOM Elements via JS

I have a GWT Application which uses the following DIV layout on its main Webpage: 我有一个GWT应用程序,其主要网页上使用以下DIV布局:

<div id="mainContainer">
    <div id="applicationHeader">
        <div id="imageLoader"></div>
        <div id="applicationHeaderMain">
            <div id="logo"></div>
            <div id="banner"></div>
            <div id="menu"></div>
        </div>
    </div>
    <div id="applicationContainer"></div>
    <div id="applicationFooter"></div>    
</div>

Both the applicationHeader and the applicationContainer use the CSS-Command width:100%; applicationHeaderapplicationContainer使用CSS命令width:100%; to adapt their size to the Browser Dimensions. 使它们的大小适应浏览器尺寸。 Inside the ApplicationContainer I have a TabPanel. 在ApplicationContainer内部,我有一个TabPanel。

Now I have a Function which resizes some Elements in one of the Tabs, and occasionally the TabPanel will exceed the Total Width of the Browser then. 现在,我有了一个可以调整选项卡之一中某些元素大小的函数,偶尔TabPanel会超过浏览器的总宽度。 The TabPanel itself will adapt properly to the Size of its Child, the mainContainer seems to do this as well, but the applicationHeader -DIV will keep its actual size altough its parent Element is resized. TabPanel本身将适当地适应其子元素的大小, mainContainer似乎也可以这样做,但是applicationHeader -DIV将在调整其父元素的大小时始终保持其实际大小。

How can I make the applicationHeader -DIV resize properly? 如何使applicationHeader -DIV正确调整大小?

Without seeing a code example it will be hard to give you a definitive answer, but I'd take a look for the following circumstances. 如果没有看到代码示例,很难为您提供确定的答案,但是我将考虑以下情况。

  1. The applicationHeader div has its css position property set to something other than the default (static). applicationHeader div的css position属性设置为默认值(静态)以外的值。 This could cause it to set its width to the full width of an element other than its direct parent. 这可能会导致其将宽度设置为除其直接父元素以外的元素的整个宽度。

  2. The applicationHeader div has a parent element other than mainContainer. applicationHeader div具有除mainContainer之外的父元素。 Perhaps some javascript is modifying the html structure dynamically and creating unexpected effects. 也许某些JavaScript正在动态修改html结构并产生意想不到的效果。

If you can provide more details I will try to help you out more. 如果您可以提供更多详细信息,我会尽力帮助您。

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

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