Getting an element's inner height

后端 未结 5 604
说谎
说谎 2020-12-08 10:04

How do you get an element\'s inner height, without padding and borders?

No jQuery, just pure JS, and a cross-browser solution (IE7 included)

5条回答
  •  误落风尘
    2020-12-08 10:32

    i had the same problem and found out there is no native cross plattform solution but the solution is easy though

    var actual_h = element.offsetHeight;
    
                if(parseInt(element.style.paddingTop.replace('px','')) > 0){
                    actual_h=actual_h -  parseInt(element.style.paddingTop.replace('px',''));
    
                }
                if(parseInt(element.style.paddingBottom.replace('px','')) > 0){
                    actual_h=actual_h -  parseInt(element.style.paddingBottom.replace('px',''));
    
                }
    

提交回复
热议问题