简体   繁体   English

加载了ajax内容的div的自动高度

[英]Auto height of div with ajax loaded content

I have a parent div with id contentPlaceHolder. 我有一个ID为contentPlaceHolder的父div。 It has a width of 640px. 宽度为640像素。 I then have content loading into this div with ajax as follows: 然后,我使用ajax将内容加载到此div中,如下所示:

function loadContent(page){
    $("#contentPlaceHolder").html('<br><br><div style="width:664px; text-align:center; font-size:12px; color:#666;"><img src="/images/loader.gif" border="0"><br>loading</div>');
    $("#contentPlaceHolder").load("/ajax/content?page=" + page);
}

<div onclick="loadContent('profile')">Profile</div>

<div id="contentPlaceHolder" style="width:640px; height:auto; text-align:left;"></div>

problem is, my parent div contentPlaceHolder does not automatically grow with the ajax content. 问题是,我的父div contentPlaceHolder不会随着ajax内容自动增长。 I tried make the div height:auto and that did not help. 我试图使div height:auto,但没有帮助。 Only way it seems to work is if I fix a height but problem with that is I cannot fix a height as the content length varies. 唯一可行的方法是固定高度,但是问题是随着内容长度的变化,无法固定高度。

Any advice as to how I can achieve this? 关于如何实现这一目标的任何建议?

Thanks 谢谢

Content loaded with .load() should automatically adjust the height of the container unless the height is specifically set on the content that was loaded, the container, or one of its parent elements. 除非已在加载的内容,容器或其父元素之一上专门设置高度,否则用.load()加载的内容应自动调整容器的高度。

Use your browser's built in developer tools ( chrome , firefox ) to inspect the container element, its contents after the ajax load, and it's parent elements. 使用浏览器的内置开发人员工具( chromefirefox )检查容器元素,加载ajax之后的内容及其父元素。 I would bet that somewhere you will find a height property set to a specific value and possibly even an overflow property set to hidden . 我敢打赌,在某个地方您会发现height属性设置为特定值,甚至可能将overflow属性设置为hidden

Here is a fiddle that demonstrates the height auto adjusting even with a min-height and overflow:hidden set (tested in chrome and firefox). 这是一个小提琴 ,它演示了即使min-heightoverflow:hidden高度也可以自动调整min-height overflow:hidden设置(在chrome和firefox中测试)。

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

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