将计算的CSS样式映射到指定的样式? [英] Mapping computed CSS styles to specified ones?

查看:132
本文介绍了将计算的CSS样式映射到指定的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以映射计算样式(由 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆