我有一个注释列表,其中的内容位于绝对定位的div中。这是设计的一部分。它们位于设置为显示的弹出框中:无,然后使用click事件淡入。
我遇到的问题是,我需要获取内部绝对内容的高度并将该高度设置为其父级,并且似乎无法使其正常工作。每个项目的注释都可以是任意长度。
我在这里做了一个小提琴,以显示我具有什么样的结构。 http://jsfiddle.net/ZTDyA/
这是结构
<div class="hidden">
<ul class="list">
<li>
<div class="inner">there is some content here</div>
<div class="base">This is a div under the .inner div</div>
</li>
<li>
<div class="inner">For the thing I have made this has to be positioned absolutely, but the content could be of any length so I need the parent to each of these inners to be set to the height of the inner div.</div>
<div class="base">This is a div under the .inner div</div>
</li>
</ul>
</div>
最佳答案
当然,您可以执行以下操作:
$('.list li').each(function() {
$(this).height( $('.inner', this).height() );
});
jsFiddle:http://jsfiddle.net/ZTDyA/1/
我没有得到的是为什么它的位置绝对正确。如果有的话,您可能要绝对定位LI。如果您对此进行详细说明,我们可以提供更好的解决方案。像这样(通过js)设置高度是不好的做法。
关于javascript - 查找绝对定位的子元素的高度并将其高度设置为其父元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15025401/