【问题标题】:Find line height within dynamically inserted element在动态插入的元素中查找行高
【发布时间】:2011-11-07 14:48:59
【问题描述】:

在我可能动态插入 DOM 的特定 div/span 中,我需要在该 DOM 元素中找到 1em 计算高度(渲染后的高度)。

只是想知道在我开始之前是否有人已经知道这样做的好方法。

【问题讨论】:

    标签: jquery html css dom browser


    【解决方案1】:

    在 jQuery 中,您需要 .css() 方法。例如,在 Stack Overflow 上:

    $(document.body).css('line-height'); //-> "12px"
    

    在“vanilla”JavaScript 中,现代浏览器需要 getComputedStyle [specs],旧版 IE 需要 currentStyle

    【讨论】:

    • 谢谢。但是,.css() 给了我normalundefined 或样式表定义的高度(如果明确指定)。我会尝试getComputedStyle() 看看是否有帮助。
    • @conqenator 在JSFiddle 上发布一个示例测试用例 - 然后其他人就可以理解你想要什么并帮助实现它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 1970-01-01
    • 2011-02-05
    • 2020-07-15
    • 2015-06-11
    • 1970-01-01
    相关资源
    最近更新 更多