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

标签 javascript jquery html css

我在使用动态内容填充 HTML div 时遇到问题。当动态数据加载到 div 中时,其高度不会扩展以适应内容。 动态内容的 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);

此处,数据是从具有字符串值的静态数组中加载的。

html div 如下:

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

当我将静态数据放入 div 中时,它会扩展以适应内容的大小。但是,动态数据并非如此。 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;


}

Screen shot for the div

如何控制我的 div 的高度以适合动态内容的大小?

最佳答案

代替 overflow:hiddenoverflow:auto

关于javascript - HTML <div> 高度不随动态内容扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19857944/

相关文章:

javascript - 你会如何使用正则表达式 javascript 来做到这一点?

javascript - 如何在 JavaScript 中使用 JIRA REST API 的基本身份验证?

javascript - 无法获取从 PHP 到 $.ajax 的 JSON 回显

javascript - Jquery 中图像轮播的多个 ID 不起作用

javascript - 相对 "position:absolute"坐标之间的动画对象

html - 具有行高的菜单使菜单在缩放时消失

javascript - tickInterval 区间内

jquery - 让一个居中的 DIV 在短暂的延迟后向下移动页面

jquery - 如何在左侧 div 超出屏幕的情况下左右滚动页面

javascript - 在 React Redux 中覆盖状态树