2014-01-12 4 views
0

'.caption'의 높이를 '. post'와 같게하려고합니다.요소의 높이를 div와 동일하게 만들기

문제는 다른 높이의 '.post'div가 여러 개 있습니다.

$(document).ready(function(){ 
    var postH = $('.post').height(); 
    $('.caption').css("height", postH); 
}); 

그것은 작동하지만 첫 번째 요소, 요소의 나머지 부분은 첫 번째 '.caption'의 높이로 남아 :

이 내가 가진 것입니다.

감사합니다.

편집 :

HTML 구조 :

<div class="content"> 

    <div class="entry"> 
     <div class="post">...</div> 
     <div class="caption">...</div> 
    </div> 

    <div class="entry"> 
     <div class="post">...</div> 
     <div class="caption">...</div> 
    </div> 

    <div class="entry"> 
     <div class="post">...</div> 
     <div class="caption">...</div> 
    </div> 

    <div class="entry"> 
     <div class="post">...</div> 
     <div class="caption">...</div> 
    </div> 

</div> 

UPDATE :

$('.entry').each(function() { 
    $(this).height($(this).find('.post').height() + 80); 
}); 

나가 수 '.entry'의 오버 플로우를 설정 : 나는 마침내 해결책을 발견

숨겨진. '+ 80'나는 잘 이해하면 '.post가'40

+0

의 사용 next에서

편집

그것에'px'를 추가합니다. – Ani

+1

css 매개 변수로 높이를 사용하지 마세요. – Gasim

+0

고마워요,하지만 여전히 작동하지 않습니다 .. 높이는 첫 번째 것에 대해서만 적용됩니다. 나는 돈을 쓰지 않습니다. ($. 이유를 모르겠다 – user3052619

답변

4

의 패딩을 가지고 있기 때문에, 당신이 많은 포스트 많은 자막이, 그래서 이것은하지 않을 수

$('.post').each(function() { 
    $(this).closest('.caption').css('height', $(this).height()); 
}); 

과 같아야입니다 closest (구조에 따라 다름)으로 작업하지만 아이디어를 얻었습니다. 당신의 갱신

대신 closest

$('.post').each(function() { 
    $(this).next('.caption').height($(this).height()); 
}); 
+0

'.caption'은 '. post'의 하위 태그가 아니므로 작동하게해야합니까? – user3052619

+0

@ user3052619 구조체의 HTML 스 니펫을 보지 않아도 짐작할 수 있습니다. –

+0

@ user3052619 DOM을 변경할 필요는 없지만 적절한 함수를 찾으려면이를 알아야합니다. '가장 가까운'이 아닐 수도 있습니다). jsfiddle에 샘플을 넣어보십시오 ... –

관련 문제