[英]jQuery: 100% height of THIS div
我如何使用.height()从.post获取高度并将其应用于.left ,每个.post都有不同的高度,所以我需要使用this() ,但找不到解决方案...我的jQuery仅捕捉第一个.post的高度。
<div class="object">
<div class="post">
<div class="left">
</div>
<div class="right">
<p>Lorem ipsum dolar sit amet</p>
</div>
</div>
</div>
$(document).ready(function(){
$height = $('.object .post').height();
$final = $height-53
$('.object .post .left').css({
height: $final
});
});
像这样:
$(document).ready(function() {
$('.left').height(function() {
return $(this).parent().height() - 53;
});
});
这会将每个.left
div的高度设置为其对应的父.post
减53px。
或只是使用CSS
.post{position:relative}
.left{position:absolute;top:0;left:0;height:100%}
开了个小提琴: http : //jsfiddle.net/filever10/rzFhL/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.