[英]get the height of a div based on other divs heights
这是一个简单的html示例:
<div id="column-5" style="height:300px;width:200px;background:red">
<div class="httwitter-thread-navigation" style="height:223px;width:100%;background:pink">
<div class="mydiv" style="width:auto;background:yellow;"></div>
</div>
我要实现的是基于以下操作为.mydiv设置高度:.mydiv的高度应为“#column-5的高度”-“ .httwitter-thread-navigation的高度-40px”
在这种情况下翻译成
300-223-40 = 37像素
如何使用JavaScript获取37px的高度?
考虑到css中可能未指定column-5或另一列的高度,因此javascript应该检测到它的innerHeights(包括边距和填充)
非常感谢
在这里提琴: http : //jsfiddle.net/omegaiori/hafn5/1/
.mydiv的高度应为“#column-5的高度”-“ .httwitter-thread-navigation的高度-40px”
那差不多算了吗?
$('.mydiv').height(function() {
return $('#column-5').height() - $('.httwitter-thread-navigation').height() - 40;
});
jQuery根据您的需要同时具有externalHeight和innerHeight 。 阅读文档。
干得好:
$(document).ready(function() {
$('.mydiv').css('height', ($('#column-5').height() - $('.httwitter-thread-navigation').height() - 40);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.