首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getComputedStyle文本装饰继承

getComputedStyle文本装饰继承
EN

Stack Overflow用户
提问于 2013-11-03 06:31:21
回答 1查看 752关注 0票数 1

getComputedStyle无法继承text-decoration属性,但可以获得font-size

Firefox 25GoogleChrome 30中失败。

注意:在Internet 10工作!

代码语言:javascript
复制
<!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>

这是我的错,还是浏览器失败了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-03 06:49:09

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19750436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档