1

絶対位置の div にコンテンツを含むコメントのリストがあります。これは設計の一部として必要でした。これらは、display: none に設定されたポップアップ ボックスにあり、クリック イベントを使用してフェード インします。

私が抱えている問題は、内部の絶対コンテンツの高さを取得し、その高さをその親に設定する必要があり、それを機能させることができないことです。各項目はコメントであるため、長さに制限はありません。

私が持っている構造の種類を示すために、ここでフィドルを作成しました。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>
4

2 に答える 2

2

もちろん、次のようなこともできます。

$('.list li').each(function() {
    $(this).height( $('.inner', this).height() );
});

jsFiddle: http://jsfiddle.net/ZTDyA/1/

私が得られないのは、なぜそれが絶対に配置されているのかということです。どちらかといえば、LI を絶対に配置したい場合があります。それについて詳しく説明していただければ、より良い解決策を提供できるかもしれません。このように (js を介して) 高さを設定するのは、あまり良い方法ではありません。

于 2013-02-22T13:32:56.580 に答える
0

これをチェックして :

$('button').on('click', function() {    
var hei=  $('.inner').height();
$('.inner').closest('li').height(hei); 
});
于 2013-02-22T13:40:24.167 に答える