将计算的CSS样式映射到指定的样式? [英] Mapping computed CSS styles to specified ones?
问题描述
有什么方法可以映射计算样式(由 window.getComputedStyle
)复制到 CSSStyleRule
> document.styleSheets ?
Is there a way to map the computed style of a dom element (as retrieved by window.getComputedStyle
) to a corresponding CSSStyleRule
in document.styleSheets
?
My ultimate goal is to retrieve specified values for dom elements (rather than computed values or actual values).
推荐答案
据我所知,只有IE(与element.currentStyle)允许JS检索指定的值,这是一个好东西在我看来。所有其他浏览器返回计算值。
As far as I know, only IE (with element.currentStyle) allows JS to retrieve the specified values, which is a good thing in my opinion. All the other browsers return the computed values.
我需要指定的值,唯一让我想到的是使一个CSS解析器映射一个元素基于元素的xpath的规则。这将是一种反转的jQuery,你将提供一个DOM元素,它会在解析所有加载的CSS后返回与它相关联的CSS规则。不幸的是,我没有时间开始项目。
I once needed the specified value and the only thing that crossed my mind was to make a CSS parser that would map an element to a rule based on the element's xpath. It would have been some kind of a reversed jQuery, where you would supply a DOM element and it would have returned the CSS rules associated with it after parsing all the loaded CSS. Unfortunately I didn't have the time to start the project.
这篇关于将计算的CSS样式映射到指定的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!