![](/img/trans.png)
[英]How to get the height of a parent div which has a child nested and they both have absolute position?
[英]Get the height of a DIV where the parent DIV has position absolute (JQuery)
在我的網頁中,有一個div.content
容器,其position: absolute
。 在父div( div.content
)內部有一個div.sub_content
。 我想使用JavaScript或JQuery提取.sub_content
高度。
在程序中,我需要計算div.sub_content
height 。
我正在使用以下代碼:
$(document).ready(function(){
var a = $('div.content div.sub_content').height();
alert(a);
});
使用$('.content .sub_content').height();
參見示例, height
為css,不包含...
$(document).ready(function(){ var a = $('.content .sub_content').height(); var b = $('.content .sub_content_noHeight').height(); alert('sub_content: ' + a + ' sub_content_noHeight: ' + b); });
.content{ position:absolute; } .sub_content{ height:150px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="content"> <div class="sub_content"> With height property in css </div> </div> <div class="content"> <div class="sub_content_noHeight"> Without height property in css </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.