2015-02-24 1341 views
1

我試圖獲取html文件的根字體大小。下面 是我的html:如何獲取html標籤的字體大小

<html> 
<head> 
    <title>el query</title> 
    <style type="text/css"> 
     html { 
      font-size: 10px; 
     } 
     html, body { 
      height: 100%; 
      width: 100%; 
      margin: 0; 
     } 
    </style> 
</head> 
<body> 
    <div id="testDivWrapper"> 
     <div id="testDiv"> 
      <div class="child"> 
       <div class="target"></div> 
      </div> 
     </div> 
    </div> 
</body> 
</html> 

,但是當我試圖讓任何字體的信息,我不能得到任何字體信息。我曾嘗試使用以下js:

document.documentElement.style.fontSize 
document.body.style.fontSize 

但我想出了空字符串。有任何想法嗎?

+1

'window.getComputedStyle(document.body).getPropertyValue('font-size');'' – chiliNUT 2015-02-24 02:41:45

回答

2
window.getComputedStyle(document.body).getPropertyValue('font-size');