在没有jquery的appendChild之后计算div高度

时间:2015-10-08 08:03:09

标签: javascript html css height appendchild

在我的私人主页上http://www.alexanderhauck.com/我使用appendChild将多个图片添加到div容器中。容器只需

即可设置
<div id="instafeed" class="grau">
    <h2 class="ueberschrift">
        Neueste Instagram Fotos
    </h2>
    <br clear="all" />
</div>

我希望容器的高度增加,以便背景覆盖图像后面的整个区域,我将其添加到循环中

document.getElementById('instafeed').appendChild(img);

相反,div返回高度116。 screenshot shows how background stops after 116px 更确切地说,我尝试使用控制台输出读取各种属性:

document.getElementById("instafeed").offsetHeight;
-> 116

document.getElementById("instafeed").clientHeight;
-> 116

document.getElementById("instafeed").style.height;
-> ""

document.getElementById("instafeed").clientHeight;
-> 116

...但没有人返回div的实际高度。我在这里错过了什么吗?据我在谷歌上搜索和搜索,大多数解决方案都依赖于jquery - 但是如果没有这个问题你会如何解决? 任何帮助是值得赞赏的,最好的情况是你的想法没有jquery - 我尝试在那里使用普通的JavaScript。 提前致谢 亚历克斯

0 个答案:

没有答案
相关问题