简体   繁体   English

将父DIV高度调整为内部内容(RSS提要)

[英]Adjust parent DIV height to inner content (RSS feeds)

I'm embedding a RSS feed into my html site using the Google Feed API. 我正在使用Google Feed API将RSS feed嵌入到html站点中。 I tried to make the parent-DIV adjust its height with jquery: 我试图用jQuery使父级DIV调整其高度:

function setHeightParent() {
                $("#Parent").height($("#feed").height() + 200);
                }

This results in a parent-DIV with a height of 200 px. 这将导致高度为200像素的父DIV。 I think the height is calculated before the "feed" div has any content therefore no height.. What am I doing wrong, how can I make it take the height of the final "feed" div? 我认为高度是在“提要” div包含任何内容之前计算的,因此没有高度。.我在做错什么,如何使它取最后的“提要” div的高度?

I got it... 我知道了...

Amir was kinda right about the delay. 阿米尔(Amir)有点延迟。

Solved it like this: 像这样解决它:

$(document).ready(function() {
    function setHeightParent() {
        $("#Parent").css("height", $("#feed").height() + 250);
    }
setTimeout(setHeightParent, 800)
});

Only specify the height of the child, the parent should scale with it. 仅指定孩子的身高,父母应与其一起缩放。

 #parent { border: 3px solid red; } #feed { height: 200px; border: 3px solid blue; } 
 <div id="parent"> <div id="feed"> </div> </div> 

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

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