Mapping computed CSS styles to specified ones?

后端 未结 1 416
生来不讨喜
生来不讨喜 2021-01-28 00:38

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

相关标签:
1条回答
  • 2021-01-28 01:07

    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.

    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.

    0 讨论(0)
提交回复
热议问题