![](/img/trans.png)
[英]Calculate height of div with absolute child divs that have no height set
[英]Get height of a div with nested absolute divs with js
我有一个div充当相对放置的容器。 在这个div中,我还有其他3个div定位为绝对值。
<head>
<style>
#container{ position:relative; }
#block1, #block2, #block3 { position:absolute; }
#block2 { top:100px; }
#block3 { top:600px; }
</style>
</head>
<div id="container">
<div id="block1"> some text </div>
<div id="block2"> some text </div>
<div id="block3"> some text </div>
</div>
如何使用js获取相对div的正确高度。
我尝试了.clientHeight和jquery .height(),但无法正常工作。
谢谢!
我想你错了。 当您将div这样放置在其他div内时,container-div将几乎没有(或没有)高度。 这是绝对定位div的原因。 它们可以放置在container-div的“外部”,并且仅用作x和y偏移量的参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.