js如何在getComputedStyle规则中获取源css规则

时间:2015-12-30 15:38:09

标签: javascript styles rules getcomputedstyle

我们知道使用window.getComputedStyle()方法我们可以得到特定元素的计算样式。 (见https://jsfiddle.net/r7sgpyt5/1/)。 我的问题是,我们如何才能知道计算样式中CSSStyleDeclaration的来源。例如在https://jsfiddle.net/r7sgpyt5/1/中我定义了一个css规则,如:

arm-linux-gnueabihf

如果我使用getComputedStyle(element,null).getPropertyValue(“color”)它返回“rgb(255,0,0)”,但我怎么知道属性“color”在css选择器中定义“#元素”。

THX!

1 个答案:

答案 0 :(得分:0)

@Tsingbo,据我所知,这是不可能的,但你可以在Chrome中尝试window.getMatchedCSSRules。

相关问题