简体   繁体   English

复制适用于元素的CSS样式

[英]copy CSS styles that apply to an element

I want to be able to get as output to the console (or something like this) all the style rules that apply to an element. 我希望能够将所有适用于元素的样式规则作为输出到控制台(或类似的东西)。 Such that for example $(_element_).css_styles(); 例如$(_element_).css_styles(); generates output like: 生成如下输出:

  • element { style } 元素 { style }
  • .class { style } .class { style }
  • super > element { style } super > element { style }
  • neighbor + element { style } 邻居 + 元素 { style }

How can I get this? 我怎么能得到这个?

edit: I built a jfiddle that looks good. 编辑:我建立了一个看起来不错的jfiddle

If you're on Chrome, you can use getMatchedCSSRules(element) . 如果您使用的是Chrome,则可以使用getMatchedCSSRules(element) If you're on FireFox (or another Gecko browser), a polyfill is available. 如果您使用的是FireFox(或其他Gecko浏览器),则可以使用polyfill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM