【问题标题】:how to get the font size of html tag [duplicate]如何获取html标签的字体大小[重复]
【发布时间】:2015-04-25 13:46:22
【问题描述】:

我正在尝试获取 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

但我想出了空字符串。有什么想法吗?

【问题讨论】:

标签: javascript css html fonts font-size


【解决方案1】:
window.getComputedStyle(document.body).getPropertyValue('font-size');

【讨论】:

    猜你喜欢
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2020-05-19
    • 2017-05-11
    相关资源
    最近更新 更多