简体   繁体   English

HTML <div> 高度不随动态内容扩展

[英]HTML <div> height not expanding with dynamic content

I am having problem with populating an HTML div with dynamic content. 我在用动态内容填充HTML div时遇到问题。 When dynamic data loads inside the div, its height is not expanding to fit the content. 当动态数据加载到div中时,其高度不会根据内容进行扩展。 The jquery code for dynamic content is: 动态内容的jQuery代码为:

$('.width_3_quarter').append('<h2>Selected Groups</h2>');
                            for(var i=0; i<userGroups.length; i++)
                            {   
                                var div=$('<div id="data"'+i+' style="display:block;">'+userGroups[i]+'</div> ');
                                $('.width_3_quarter').append(div);
                            }

                            var selCat=$('<div id="selectedCat"><span style="font-weight:bold; text-decoration:underline;">Groups Selected </span></div>');
                            var label=$('<label style="margin-top:-1px; margin-bottom:0px;position:absolute;font-weight:bold;text-decoration:underline;">Available Groups </label>');

                            var selectedData=$('<div id="myData"></div>');

                            var select=$('<select id="grpSelect" name="grpSelect" multiple="multiple"> </select>');
                            for(var i=0;i<listGroups.length; i++)
                            {
                                var option=$('<option value="'+listGroups[i]+'">'+listGroups[i]+'</option>');
                                select.append(option);
                            }


                            var button=$('<input type="button" value="submit" id="valSubmit" onclick="addGrp();"/>');

                    selCat.append(selectedData);
                $('.width_3_quarter').append(label);
                selCat.prepend(button);
                $('.width_3_quarter').append(select);
                $('.width_3_quarter').append(selCat);

Here, the data is getting loaded from a static array with string values. 在这里,数据是从带有字符串值的静态数组中加载的。

The html div is as: html div如下:

<div class="module width_3_quarter" style="clear:both;">

When I put static data inside the div, it is expanding to fit the size of the content. 当我将静态数据放入div时,它正在扩展以适合内容的大小。 However, its not the case with dynamic data. 但是,动态数据并非如此。 The CSS is: CSS是:

.width_3_quarter {
width: 73%;
    margin-right: 0;
    min-height: 462px;
    font-weight: normal;
    display: inline-block;
    text-indent: 20px;
    overflow: hidden;
    color: #1F1F20;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #fff;
    line-height: 36px;
    font-size: 18px;


}

div的屏幕截图

How can I control my div's height to fit the size of the dynamic content? 如何控制div的高度以适合动态内容的大小?

而不是overflow:hidden执行overflow:auto

尝试将最小高度更改为100%:

min-height:100%;

What about doing this 那怎么办

overflow: hidden;
overflow-y: auto;

From experience you have to specify the axis you want overflow to work on sometimes 根据经验,您有时必须指定要溢出的轴

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

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