javascript - getComputedStyle 文本修饰继承

标签 javascript css google-chrome firefox

getComputedStyle获取text-decoration属性继承失败,但可以获取font-size

Firefox 25GoogleChrome 30 中失败。

Note: In Internet Explorer 10 work!

<!DOCTYPE html>
<html>
    <style>
        #parent
        {
            font-size: 38px;
            text-decoration: underline;
        }
    </style>
<body>
    <div id="parent">
        <p id="child">Test</p>
    </div>
    <script>
        var elem = document.getElementById("child");

        document.write("text-decoration:"+window.getComputedStyle(elem).getPropertyValue("text-decoration"));
        document.write("<br>");
        document.write("text-decoration:"+document.defaultView.getComputedStyle(elem).getPropertyValue("text-decoration"));
        document.write("<hr>");
        document.write("font-size:"+window.getComputedStyle(elem).getPropertyValue("font-size"));
        document.write("<br>");
        document.write("font-size:"+document.defaultView.getComputedStyle(elem).getPropertyValue("font-size"));
    </script>
</body>
</html>

是我的错,还是浏览器的问题?

最佳答案

text-decoration 不应继承,即使父文本装饰会影响子文本。这与继承的 font-size 不同。

话虽如此,这看起来确实像一个 IE 错误。虽然 window.getComputedStyle() 在 IE10 中报告为继承,但值得注意的是 F12 开发人员工具另有说明。

引用资料:

https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration

http://reference.sitepoint.com/css/text-decoration

关于javascript - getComputedStyle 文本修饰继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19750436/

相关文章:

javascript - Chrome 历史记录页面覆盖会在每次页面加载时触发?

javascript - Chrome 和 JS onclick 函数?

javascript - Bootstrap Modal - 根据 iframe 高度调整模态大小

c# - Typeahead.js 和 Bloodhound.js 与 C# WebForms WebMethod 的集成

javascript - 无法将旧的 reCaptcha 代码居中

java - 使用自定义 CSS 将 HTML 文件加载到 WebView

javascript - Chrome 扩展 - 在全屏视频顶部显示自定义通知/弹出窗口(HTML 元素)

javascript - 通过过渡更改组件 props

javascript - 通过 knockout 绑定(bind)到下拉菜单?

HTML/CSS - 打印样式,背景不会显示?