找到绝对定位的子元素的高度并设置它's到其父项的高度
Find the height of absolutely positioned child element and setting it's height to its parent
我有一个注释列表,其中的内容位于绝对位置的div中。这是设计中所必需的。它们在一个弹出框中,设置为显示:无,然后使用单击事件淡入。
我遇到的问题是,我需要获得内部绝对内容的高度,并将该高度设置为其父内容,但似乎无法使其发挥作用。每个项目都可以是任意长度的,因为它们是注释。
我在这里做了一把小提琴来展示我的结构。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/
我不明白的是为什么它的位置是绝对的。如果有什么不同的话,你可能想绝对定位李。也许如果你详细说明一下,我们可以提供一个更好的解决方案。像这样设置高度(通过js)是一种糟糕的做法。
检查此项:
$('button').on('click', function() {
var hei= $('.inner').height();
$('.inner').closest('li').height(hei);
});
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- CSS-如何定位内容数据标题
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 在Jquery detachment()和appendTo()之后定位元素
- 困在逻辑中试图定位动态的东西
- 单击页面上的链接后高度发生变化
- 不加载宽度和高度的角度pintura
- 将元件定位在特定高度
- 幻灯片JS高度和按钮定位问题
- 元素上的自动高度,仅具有相对定位的子元素
- 根据浮动元素的高度定位 CSS 元素
- 定位图像基于浏览器的宽度和高度
- CSS定位多个元素的全宽度和高度
- 绝对定位元素的计算高度
- 地理定位:是否有办法发现有人正在上升的高度
- 找到绝对定位的子元素的高度并设置它's到其父项的高度
- 正在计算绝对定位的嵌套子项的高度
- Javascript表单验证未执行,输入文本框高度光标定位未设置为顶部