簡體   English   中英

如何使這兩個div具有相同的高度?

[英]How do I make these two divs the same height?

我有一些內容組,由兩個div組成,兩個div包含文本,我希望每組的第二個div匹配第一個的高度。

DEMO

HTML(不幸的是不能更改)

<!-- group one -->
<div class="item">
    .... content here
</div>

<div class="item_open">
    .... content here too
</div>

<!-- group two -->
<div class="item">
    .... completely different content here
</div>

<div class="item_open">
    .... some more content here too
</div>

嘗試這個

$('.item_open').height(function(){
 return $(this).prev().height();
});

DEMO

小提琴演示

$('.item_open').height(function(){
    return $(this).prev().height();
});

。高度()

.prev()

我很確定你在尋找的東西可以在這里找到: http//www.ejeliot.com/blog/61

(使用CSS而不是JQuery)

這是一個使用jQuery實現這一目標的小提琴。

http://jsfiddle.net/59Rhn/4/

$(".item_open").each(function(){
    $(this).height($(this).prev().height());
});

如果您無法更改HTML,可以嘗試這種方式..

var $item = $(document).find('.item'); // find first tag item
var $itemNext = $item.next();          // return item_open
$($item, $itemNext).css({
   height: '100px'
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM